Browse Source

remove old color-picker views

main
Distopico Vegan 4 years ago
parent
commit
d4715ed7e2
No known key found for this signature in database GPG Key ID: 98093A8072546BF3
4 changed files with 109 additions and 109 deletions
  1. +3
    -0
      app/src/main/AndroidManifest.xml
  2. +15
    -48
      app/src/main/java/org/dystopia/email/ColorDialogFragment.java
  3. +65
    -28
      app/src/main/java/org/dystopia/email/FragmentAccount.java
  4. +26
    -33
      app/src/main/res/layout/fragment_account.xml

+ 3
- 0
app/src/main/AndroidManifest.xml View File

@ -8,6 +8,9 @@
<uses-permission android:name="android.permission.READ_CONTACTS" /> <uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" /> <uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" /> <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission
android:name="android.permission.USE_CREDENTIALS"
android:maxSdkVersion="22" />
<uses-permission android:name="android.permission.WAKE_LOCK" /> <uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-feature <uses-feature


+ 15
- 48
app/src/main/java/org/dystopia/email/ColorDialogFragment.java View File

@ -22,14 +22,12 @@ package org.dystopia.email;
import android.app.Dialog; import android.app.Dialog;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color; import android.graphics.Color;
import android.os.Bundle; import android.os.Bundle;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.fragment.app.DialogFragment; import androidx.fragment.app.DialogFragment;
import androidx.fragment.app.FragmentResultListener;
import com.flask.colorpicker.ColorPickerView; import com.flask.colorpicker.ColorPickerView;
import com.flask.colorpicker.OnColorChangedListener; import com.flask.colorpicker.OnColorChangedListener;
@ -39,53 +37,23 @@ import com.flask.colorpicker.builder.ColorPickerDialogBuilder;
import static android.app.Activity.RESULT_OK; import static android.app.Activity.RESULT_OK;
public class ColorDialogFragment extends DialogFragment { public class ColorDialogFragment extends DialogFragment {
private static int requestSequence = 0;
public static final String DIALOG_COLOR = "dialog:color:select";
private boolean sent = false; private boolean sent = false;
private String requestKey = null;
private String targetRequestKey;
private int targetRequestCode;
private int color; private int color;
public String getRequestKey() {
if (requestKey == null)
requestKey = getClass().getName() + "_" + (++requestSequence);
return requestKey;
}
@Override @Override
public void onCreate(@Nullable Bundle savedInstanceState) { public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
if (savedInstanceState != null) { if (savedInstanceState != null) {
requestKey = savedInstanceState.getString("dialog:request");
targetRequestKey = savedInstanceState.getString("dialog:key");
targetRequestCode = savedInstanceState.getInt("dialog:code");
color = savedInstanceState.getInt("dialog:color");
} }
getParentFragmentManager().setFragmentResultListener(getRequestKey(), this, new FragmentResultListener() {
@Override
public void onFragmentResult(@NonNull String requestKey, @NonNull Bundle result) {
try {
result.setClassLoader(ApplicationEx.class.getClassLoader());
int requestCode = result.getInt("requestCode");
int resultCode = result.getInt("resultCode");
Intent data = new Intent();
data.putExtra("args", result);
onActivityResult(requestCode, resultCode, data);
} catch (Throwable ex) {
// LOg
}
}
});
} }
@Override @Override
public void onSaveInstanceState(@NonNull Bundle outState) { public void onSaveInstanceState(@NonNull Bundle outState) {
outState.putInt("dialog:color", color); outState.putInt("dialog:color", color);
outState.putString("dialog:request", requestKey);
outState.putString("dialog:key", targetRequestKey);
outState.putInt("dialog:code", targetRequestCode);
super.onSaveInstanceState(outState); super.onSaveInstanceState(outState);
} }
@ -140,18 +108,17 @@ public class ColorDialogFragment extends DialogFragment {
} }
protected void sendResult(int resultCode) { protected void sendResult(int resultCode) {
if (sent) {
return;
}
sent = true;
if (targetRequestKey != null) {
Bundle args = getArguments();
if (args == null) {
args = new Bundle();
}
args.putInt("requestCode", targetRequestCode);
args.putInt("resultCode", resultCode);
getParentFragmentManager().setFragmentResult(targetRequestKey, args);
}
if (sent) {
return;
}
sent = true;
Bundle args = getArguments();
if (args == null) {
args = new Bundle();
}
args.putInt("resultCode", resultCode);
getParentFragmentManager().setFragmentResult(DIALOG_COLOR, args);
dismiss();
} }
} }

+ 65
- 28
app/src/main/java/org/dystopia/email/FragmentAccount.java View File

@ -21,13 +21,13 @@ package org.dystopia.email;
*/ */
import static android.accounts.AccountManager.newChooseAccountIntent; import static android.accounts.AccountManager.newChooseAccountIntent;
import static android.app.Activity.RESULT_OK;
import android.Manifest; import android.Manifest;
import android.accounts.Account; import android.accounts.Account;
import android.accounts.AccountManager; import android.accounts.AccountManager;
import android.accounts.AccountManagerCallback; import android.accounts.AccountManagerCallback;
import android.accounts.AccountManagerFuture; import android.accounts.AccountManagerFuture;
import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
@ -61,8 +61,10 @@ import android.widget.Spinner;
import android.widget.TextView; import android.widget.TextView;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import androidx.constraintlayout.widget.Group; import androidx.constraintlayout.widget.Group;
import androidx.core.content.ContextCompat; import androidx.core.content.ContextCompat;
import androidx.fragment.app.FragmentResultListener;
import androidx.lifecycle.Observer; import androidx.lifecycle.Observer;
import com.google.android.material.snackbar.Snackbar; import com.google.android.material.snackbar.Snackbar;
import com.google.android.material.textfield.TextInputLayout; import com.google.android.material.textfield.TextInputLayout;
@ -105,10 +107,9 @@ public class FragmentAccount extends FragmentEx {
private TextView tvName; private TextView tvName;
private EditText etName; private EditText etName;
private ViewButtonColor btnColor;
private View vwColor;
private ImageView ibColorDefault;
private ViewButtonColor btnColor;
private ImageView ibColorReset;
private EditText etSignature; private EditText etSignature;
private CheckBox cbSynchronize; private CheckBox cbSynchronize;
@ -141,8 +142,6 @@ public class FragmentAccount extends FragmentEx {
private int color = Color.TRANSPARENT; private int color = Color.TRANSPARENT;
private String authorized = null; private String authorized = null;
private static final int REQUEST_COLOR = 1;
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
@ -150,6 +149,13 @@ public class FragmentAccount extends FragmentEx {
// Get arguments // Get arguments
Bundle args = getArguments(); Bundle args = getArguments();
id = (args == null ? -1 : args.getLong("id", -1)); id = (args == null ? -1 : args.getLong("id", -1));
getParentFragmentManager().setFragmentResultListener(ColorDialogFragment.DIALOG_COLOR, this, new FragmentResultListener() {
@Override
public void onFragmentResult(@NonNull String requestKey, @NonNull Bundle result) {
setAccountColor(result);
}
});
} }
@Override @Override
@ -179,14 +185,12 @@ public class FragmentAccount extends FragmentEx {
tilPassword = view.findViewById(R.id.tilPassword); tilPassword = view.findViewById(R.id.tilPassword);
btnAuthorize = view.findViewById(R.id.btnAuthorize); btnAuthorize = view.findViewById(R.id.btnAuthorize);
btnAdvanced = view.findViewById(R.id.btnAdvanced); btnAdvanced = view.findViewById(R.id.btnAdvanced);
etName = view.findViewById(R.id.etName); etName = view.findViewById(R.id.etName);
btnColor = view.findViewById(R.id.btnColor); btnColor = view.findViewById(R.id.btnColor);
tvName = view.findViewById(R.id.tvName); tvName = view.findViewById(R.id.tvName);
vwColor = view.findViewById(R.id.vwColor);
ibColorDefault = view.findViewById(R.id.ibColorDefault);
ibColorReset = view.findViewById(R.id.ibColorReset);
etSignature = view.findViewById(R.id.etSignature); etSignature = view.findViewById(R.id.etSignature);
cbSynchronize = view.findViewById(R.id.cbSynchronize); cbSynchronize = view.findViewById(R.id.cbSynchronize);
@ -372,8 +376,8 @@ public class FragmentAccount extends FragmentEx {
} }
}); });
vwColor.setBackgroundColor(color);
vwColor.setOnClickListener(
btnColor.setColor(color);
btnColor.setOnClickListener(
new View.OnClickListener() { new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
@ -384,16 +388,16 @@ public class FragmentAccount extends FragmentEx {
ColorDialogFragment fragment = new ColorDialogFragment(); ColorDialogFragment fragment = new ColorDialogFragment();
fragment.setArguments(args); fragment.setArguments(args);
fragment.setTargetFragment(FragmentAccount.this, REQUEST_COLOR);
fragment.show(getParentFragmentManager(), "account:color"); fragment.show(getParentFragmentManager(), "account:color");
} }
}); });
ibColorDefault.setOnClickListener(
ibColorReset.setOnClickListener(
new View.OnClickListener() { new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
setColor(Color.TRANSPARENT);
btnColor.setColor(Color.TRANSPARENT);
ibColorReset.setVisibility(View.GONE);
} }
}); });
@ -1049,7 +1053,7 @@ public class FragmentAccount extends FragmentEx {
Helper.setViewsEnabled(view, true); Helper.setViewsEnabled(view, true);
setColor(color);
btnColor.setColor(color);
etSignature.setHint(R.string.title_optional); etSignature.setHint(R.string.title_optional);
etSignature.setEnabled(true); etSignature.setEnabled(true);
@ -1087,13 +1091,55 @@ public class FragmentAccount extends FragmentEx {
}); });
} }
/**
* Set base account to button
* @param result - color dialog data from {@link FragmentResultListener} result callback
*/
private void setAccountColor(Bundle result) {
try {
int resultCode = result.getInt("resultCode");
if (resultCode == RESULT_OK) {
color = result.getInt("color");
btnColor.setColor(color);
ibColorReset.setVisibility(View.VISIBLE);
}
} catch (Throwable ex) {
Log.e(Helper.TAG, "Set account color error: " + ex + "\n" + Log.getStackTraceString(ex));
}
}
private void selectAccount() { private void selectAccount() {
Log.i(Helper.TAG, "Select account"); Log.i(Helper.TAG, "Select account");
Provider provider = (Provider) spProvider.getSelectedItem(); Provider provider = (Provider) spProvider.getSelectedItem();
if (provider.type != null) { if (provider.type != null) {
startActivityForResult(
newChooseAccountIntent(null, null, new String[] {provider.type}, null, null, null, null),
ActivitySetup.REQUEST_CHOOSE_ACCOUNT);
Intent intent = null;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
intent = newChooseAccountIntent(
null,
null,
new String[] {provider.type},
null,
null,
null,
null
);
} else {
intent = newChooseAccountIntent(
null,
null,
new String[]{provider.type},
false,
null,
null,
null,
null
);
}
PackageManager pm = getContext().getPackageManager();
if (intent.resolveActivity(pm) == null) { // system whitelisted
throw new IllegalArgumentException(getString(R.string.title_no_viewer, intent));
}
startActivityForResult(intent, ActivitySetup.REQUEST_CHOOSE_ACCOUNT);
} }
} }
@ -1112,7 +1158,7 @@ public class FragmentAccount extends FragmentEx {
Log.i( Log.i(
Helper.TAG, Helper.TAG,
"Activity result request=" + requestCode + " result=" + resultCode + " data=" + data); "Activity result request=" + requestCode + " result=" + resultCode + " data=" + data);
if (resultCode == Activity.RESULT_OK) {
if (resultCode == RESULT_OK) {
if (requestCode == ActivitySetup.REQUEST_CHOOSE_ACCOUNT) { if (requestCode == ActivitySetup.REQUEST_CHOOSE_ACCOUNT) {
String name = data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME); String name = data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME);
String type = data.getStringExtra(AccountManager.KEY_ACCOUNT_TYPE); String type = data.getStringExtra(AccountManager.KEY_ACCOUNT_TYPE);
@ -1157,15 +1203,6 @@ public class FragmentAccount extends FragmentEx {
} }
} }
private void setColor(int color) {
FragmentAccount.this.color = color;
GradientDrawable border = new GradientDrawable();
border.setColor(color);
border.setStroke(5, Helper.resolveColor(getContext(), R.attr.colorSeparator));
vwColor.setBackground(border);
}
private void setFolders(List<EntityFolder> folders) { private void setFolders(List<EntityFolder> folders) {
final Collator collator = Collator.getInstance(Locale.getDefault()); final Collator collator = Collator.getInstance(Locale.getDefault());
collator.setStrength(Collator.SECONDARY); // Case insensitive, process accents etc collator.setStrength(Collator.SECONDARY); // Case insensitive, process accents etc


+ 26
- 33
app/src/main/res/layout/fragment_account.xml View File

@ -220,48 +220,41 @@
android:inputType="textPassword" /> android:inputType="textPassword" />
</com.google.android.material.textfield.TextInputLayout> </com.google.android.material.textfield.TextInputLayout>
<View
android:id="@+id/vwColor"
<LinearLayout
android:id="@+id/colorContainer"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tilPassword">
<org.dystopia.email.ViewButtonColor
android:id="@+id/btnColor"
style="?android:attr/buttonStyleSmall"
android:layout_width="@dimen/color_pick" android:layout_width="@dimen/color_pick"
android:layout_height="@dimen/color_pick" android:layout_height="@dimen/color_pick"
android:layout_marginTop="@dimen/base_margin"
android:layout_marginStart="@dimen/content_margin"
android:layout_marginStart="@dimen/margin_sm"
android:background="@color/colorAccent" android:background="@color/colorAccent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tilPassword" />
<ImageView
android:id="@+id/ibColorDefault"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_marginTop="12dp"
android:src="@drawable/baseline_delete_24"
app:layout_constraintBottom_toBottomOf="@id/vwColor"
app:layout_constraintStart_toEndOf="@id/vwColor"
app:layout_constraintTop_toBottomOf="@id/tilPassword" />
android:tag="disable" />
<TextView
<TextView
android:id="@+id/tvColor" android:id="@+id/tvColor"
android:layout_width="wrap_content"
android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:paddingHorizontal="@dimen/padding_sm"
android:layout_weight="1"
android:text="@string/title_color" android:text="@string/title_color"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/etName" />
android:textAppearance="@style/TextAppearance.AppCompat.Small" />
<org.dystopia.email.ViewButtonColor
android:id="@+id/btnColor"
style="?android:attr/buttonStyleSmall"
<ImageView
android:id="@+id/ibColorReset"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="6dp"
android:paddingHorizontal="6dp"
android:tag="disable"
android:text="@string/title_select"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvColor" />
android:layout_gravity="right"
android:src="@drawable/baseline_close_24"
android:visibility="invisible" />
</LinearLayout>
<Button <Button
android:id="@+id/btnAdvanced" android:id="@+id/btnAdvanced"
@ -273,7 +266,7 @@
android:minHeight="0dp" android:minHeight="0dp"
android:text="@string/title_setup_advanced" android:text="@string/title_setup_advanced"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/vwColor" />
app:layout_constraintTop_toBottomOf="@id/colorContainer" />
<!-- advanced --> <!-- advanced -->


Loading…
Cancel
Save