Added configure method for avaterview. Added dialgoue in preferences for qr code

This commit is contained in:
Keith Holliday 2016-08-12 14:27:06 -05:00
parent e0632ee6e2
commit 4bc2ace8f2
10 changed files with 78 additions and 31 deletions

View file

@ -15,14 +15,6 @@
</FrameLayout>
<LinearLayout
android:id="@+id/qrLinearLayout"
android:layout_width="match_parent"
android:layout_height="350dp"
android:layout_gravity="center">
<include layout="@layout/qr_code" />
</LinearLayout>
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"

View file

@ -3,7 +3,7 @@
android:orientation="vertical"
android:id="@+id/qrLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"

View file

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<include
layout="@layout/qr_code" />
<Button
android:id="@+id/dialogButtonOK"
android:layout_width="40dp"
android:layout_height="wrap_content"
android:text="Ok"
android:layout_marginTop="5dp"
android:layout_marginRight="5dp"
android:layout_below="@+id/qrLayout"
/>
</RelativeLayout>

View file

@ -15,6 +15,7 @@
<string name="SP_userID_summary">Your User ID</string>
<string name="SP_APIToken_title">API Token</string>
<string name="SP_APIToken_summary">Your API Token</string>
<string name="SP_user_qr_code">Your QR Code</string>
<string name="PS_contact_title">Contact me</string>
<string name="unknown_error">An error happened…</string>
<string name="pref_account_header">Account</string>
@ -381,5 +382,6 @@ To start, which parts of your life do you want to improve?</string>
<string name="qr_album_name">habitica</string>
<string name="qr_file_name"> habitrpg-qr-code.jpg</string>
<string name="qr_save_message">QR code saved at </string>
<string name="qr_dialogue_title">Your QR Code</string>
</resources>

View file

@ -46,6 +46,14 @@
android:shouldDisableView="false"
android:summary="@string/SP_APIToken_summary"/>
<Preference
android:key="@string/SP_user_qr_code"
android:title="@string/SP_user_qr_code"
android:selectable="true"
android:persistent="false"
android:shouldDisableView="false"
android:summary="@string/SP_user_qr_code"/>
</PreferenceCategory>
</PreferenceScreen>

View file

@ -1,5 +1,6 @@
package com.habitrpg.android.habitica.helpers;
import android.app.Dialog;
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
@ -12,6 +13,7 @@ import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import com.habitrpg.android.habitica.R;
@ -37,6 +39,7 @@ public class QrCodeManager {
//@TODO: Allow users to set other content
private String content;
private String userId;
private Context context;
private ImageView qrCodeImageView;
@ -65,7 +68,7 @@ public class QrCodeManager {
}
};
public QrCodeManager(Context context, LinearLayout qrLayout) {
public QrCodeManager(Context context) {
this.context = context;
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this.context);
@ -75,18 +78,22 @@ public class QrCodeManager {
this.fileName = this.context.getString(R.string.qr_file_name);
this.saveMessage = this.context.getString(R.string.qr_save_message);
this.content = userId;
this.userId = userId;
}
public void setUpView(LinearLayout qrLayout) {
this.qrCodeImageView = (ImageView) qrLayout.findViewById(R.id.QRImageView);
this.qrCodeDownloadButton = (Button) qrLayout.findViewById(R.id.QRDownloadButton);
this.avatarView = (AvatarView) qrLayout.findViewById(R.id.avatarView);
this.avatarView.configureView(false, false, false);
this.qrCodeWrapper = (FrameLayout) qrLayout.findViewById(R.id.qrCodeWrapper);
this.content = userId;
//@TODO: Move to user helper/model
new Select()
.from(HabitRPGUser.class)
.where(Condition.column("id")
.eq(userId))
.eq(userId))
.async()
.querySingle(userTransactionListener);
@ -146,4 +153,23 @@ public class QrCodeManager {
file.mkdirs();
return file;
}
public void showDialogue() {
final Dialog dialog = new Dialog(context);
dialog.setContentView(R.layout.qr_dialogue);
dialog.setTitle(R.string.qr_dialogue_title);
LinearLayout qrLayout = (LinearLayout) dialog.findViewById(R.id.qrLayout);
this.setUpView(qrLayout);
Button dialogButton = (Button) dialog.findViewById(R.id.dialogButtonOK);
dialogButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
});
dialog.show();
}
}

View file

@ -91,6 +91,12 @@ public class AvatarView extends View {
isOrphan = true;
}
public void configureView(boolean showBackground, boolean showMount, boolean showPet) {
this.showBackground = showBackground;
this.showMount = showMount;
this.showPet = showPet;
}
private void init(AttributeSet attrs, int defStyle) {
// Load attributes
final TypedArray a = getContext().obtainStyledAttributes(

View file

@ -27,9 +27,6 @@ public class PrefsActivity extends BaseActivity implements
@BindView(R.id.toolbar)
Toolbar toolbar;
@BindView(R.id.qrLinearLayout)
LinearLayout qrLinearLayout;
// TODO:
// This method should be moved to HabiticaApplication
public static HostConfig fromContext(Context ctx) {
@ -57,14 +54,6 @@ public class PrefsActivity extends BaseActivity implements
getSupportFragmentManager().beginTransaction()
.add(R.id.fragment_container, new PreferencesFragment())
.commit();
qrLinearLayout.setVisibility(View.INVISIBLE);
}
@Override
public void onBackPressed() {
super.onBackPressed();
qrLinearLayout.setVisibility(View.INVISIBLE);
}
@Override

View file

@ -25,6 +25,8 @@ import java.util.Map;
public class AccountDetailsFragment extends BasePreferencesFragment {
private QrCodeManager qrCodeManager;
@Override
protected void setupPreferences() {
for (Map.Entry<String, ?> preference : getPreferenceScreen().getSharedPreferences().getAll().entrySet()) {
@ -34,20 +36,22 @@ public class AccountDetailsFragment extends BasePreferencesFragment {
}
}
LinearLayout qrLinearLayout = (LinearLayout) getActivity().findViewById(R.id.qrLinearLayout);
qrLinearLayout.setVisibility(View.VISIBLE);
LinearLayout qrLayout = (LinearLayout) getActivity().findViewById(R.id.qrLayout);
QrCodeManager qrCodeManager = new QrCodeManager(this.getContext(), qrLayout);
qrCodeManager = new QrCodeManager(this.getContext());
}
protected List<String> getAccountDetailsPreferences() {
return Arrays.asList(getString(R.string.SP_username), getString(R.string.SP_email),
getString(R.string.SP_APIToken), getString(R.string.SP_userID));
getString(R.string.SP_APIToken), getString(R.string.SP_userID), getString(R.string.SP_user_qr_code));
}
@Override
public boolean onPreferenceTreeClick(Preference preference) {
Log.v("keith", preference.getKey());
if (preference.getKey().equals(getString(R.string.SP_user_qr_code))) {
qrCodeManager.showDialogue();
}
ClipboardManager clipMan = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
clipMan.setPrimaryClip(ClipData.newPlainText(preference.getKey(), preference.getSummary()));
Toast.makeText(getActivity(), "Copied " + preference.getKey() + " to clipboard.", Toast.LENGTH_SHORT).show();

View file

@ -117,7 +117,8 @@ public class GroupInformationFragment extends BaseFragment {
bossRageBar = DataBindingUtil.bind(view.findViewById(R.id.bossRageBar));
if (this.group == null) {
new QrCodeManager(this.getContext(), qrLayout);
QrCodeManager qrCodeManager = new QrCodeManager(this.getContext());
qrCodeManager.setUpView(qrLayout);
}
if (user.getParty().getId() != null) {