Move default SMS and system import to "reminders"

// FREEBIE
Closes #1730
This commit is contained in:
Jake McGinty 2014-07-22 17:27:05 -10:00 committed by Moxie Marlinspike
parent acc7c4c1c6
commit 7d688846f9
17 changed files with 227 additions and 33 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="@color/light_button_highlight" />
<item android:drawable="@color/light_button" />
</selector>

View File

@ -0,0 +1,82 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout android:id="@+id/container"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:background="?reminder_header_background">
<ImageView android:id="@+id/icon"
android:layout_width="50dp"
android:layout_height="50dp"
android:src="@drawable/sms_selection_icon"
android:padding="5dp"/>
<LinearLayout android:id="@+id/reminder"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_margin="10dp"
android:orientation="vertical">
<TextView android:id="@+id/reminder_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:textColor="@color/white"
android:textSize="18sp"/>
<TextView android:id="@+id/reminder_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-light"
android:textColor="@color/white"
android:textSize="16sp"/>
</LinearLayout>
<LinearLayout android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="right"
android:layout_marginLeft="15dp"
android:orientation="vertical">
<LinearLayout android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="top">
<ImageButton android:id="@+id/cancel"
android:layout_width="40dp"
android:layout_height="40dp"
android:padding="10dp"
android:background="@drawable/touch_highlight_background"
android:src="@drawable/ic_menu_remove_holo_light"/>
</LinearLayout>
<LinearLayout android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="bottom">
<Button android:id="@+id/ok"
android:layout_width="60sp"
android:layout_height="40sp"
android:gravity="center_vertical|center_horizontal"
android:background="@drawable/light_touch_highlight_background"
android:fontFamily="sans-serif-light"
android:textColor="@color/white"
android:text="@string/yes"
android:padding="2dp"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>

View File

@ -57,6 +57,8 @@
<attr name="navigation_drawer_icons" format="reference"/>
<attr name="navigation_drawer_shadow" format="reference"/>
<attr name="reminder_header_background" format="color"/>
<attr name="menu_new_conversation_icon" format="reference" />
<attr name="menu_new_group_icon" format="reference" />
<attr name="menu_search_icon" format="reference" />

View File

@ -15,7 +15,8 @@
<color name="textsecure_holo_blue_light">#ff33b5e5</color>
<color name="touch_highlight">#400099cc</color>
<color name="light_button">#33ffffff</color>
<color name="light_button_highlight">#66ffffff</color>
<color name="conversation_item_sent_background_dark">#ff284e0a</color>
<color name="conversation_item_sent_background_light">#ff64a926</color>
<color name="conversation_item_sent_shadow_light">#ffd5d5d5</color>

View File

@ -856,6 +856,11 @@
<!-- verify_keys -->
<string name="verify_keys__menu_verified">Verified</string>
<!-- reminder_header -->
<string name="reminder_header_sms_default_title">Use as default SMS app?</string>
<string name="reminder_header_sms_default_text">TextSecure is not currently your default SMS app.</string>
<string name="reminder_header_sms_import_title">Import system SMS?</string>
<string name="reminder_header_sms_import_text">TextSecure can copy your phone\'s SMS messages into its encrypted database.</string>
<!-- EOF -->
</resources>

View File

@ -79,6 +79,8 @@
<item name="menu_info_icon">@drawable/ic_dialog_info_holo_light</item>
<item name="menu_forward_icon">@drawable/ic_action_forward_holo_light</item>
<item name="menu_save_icon">@drawable/ic_action_save_holo_light</item>
<item name="reminder_header_background">#ff5a8800</item>
</style>
<style name="TextSecure.LightTheme.NavigationDrawer"
@ -160,6 +162,8 @@
<item name="menu_info_icon">@drawable/ic_dialog_info_holo_dark</item>
<item name="menu_forward_icon">@drawable/ic_action_forward_holo_dark</item>
<item name="menu_save_icon">@drawable/ic_action_save_holo_dark</item>
<item name="reminder_header_background">#ff385400</item>
</style>
<style name="TextSecure.DarkTheme.NavigationDrawer"

View File

@ -85,8 +85,6 @@ public class ConversationListActivity extends PassphraseRequiredSherlockFragment
super.onResume();
dynamicTheme.onResume(this);
dynamicLanguage.onResume(this);
initializeDefaultMessengerCheck();
}
@Override
@ -296,15 +294,6 @@ public class ConversationListActivity extends PassphraseRequiredSherlockFragment
this.fragment.setMasterSecret(masterSecret);
}
private void initializeDefaultMessengerCheck() {
if (!TextSecurePreferences.hasPromptedDefaultSmsProvider(this) && !Util.isDefaultSmsProvider(this)) {
TextSecurePreferences.setPromptedDefaultSmsProvider(this, true);
Intent intent = new Intent(Telephony.Sms.Intents.ACTION_CHANGE_DEFAULT);
intent.putExtra(Telephony.Sms.Intents.EXTRA_PACKAGE_NAME, getPackageName());
startActivity(intent);
}
}
class DrawerToggle extends ActionBarDrawerToggle {
public DrawerToggle(Activity activity, DrawerLayout drawerLayout,

View File

@ -16,21 +16,33 @@
*/
package org.thoughtcrime.securesms;
import android.annotation.TargetApi;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.Cursor;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Build.VERSION_CODES;
import android.os.Bundle;
import android.provider.Telephony;
import android.support.v4.app.LoaderManager;
import android.support.v4.content.Loader;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.CursorAdapter;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import com.actionbarsherlock.app.SherlockListFragment;
import com.actionbarsherlock.view.ActionMode;
@ -43,9 +55,11 @@ import org.thoughtcrime.securesms.database.DatabaseFactory;
import org.thoughtcrime.securesms.database.loaders.ConversationListLoader;
import org.thoughtcrime.securesms.notifications.MessageNotifier;
import org.thoughtcrime.securesms.recipients.Recipients;
import org.thoughtcrime.securesms.service.ApplicationMigrationService;
import org.thoughtcrime.securesms.util.Dialogs;
import org.thoughtcrime.securesms.util.TextSecurePreferences;
import org.whispersystems.textsecure.crypto.MasterSecret;
import org.whispersystems.textsecure.util.Util;
import org.thoughtcrime.securesms.util.Util;
import java.util.Set;
@ -57,12 +71,20 @@ public class ConversationListFragment extends SherlockListFragment
private ConversationSelectedListener listener;
private MasterSecret masterSecret;
private ActionMode actionMode;
private View reminderView;
private String queryFilter = "";
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle) {
return inflater.inflate(R.layout.conversation_list_fragment, container, false);
final View view = inflater.inflate(R.layout.conversation_list_fragment, container, false);
reminderView = LayoutInflater.from(getActivity()).inflate(R.layout.reminder_header, null);
return view;
}
@Override
public void onDestroyView() {
super.onDestroyView();
getListView().setAdapter(null);
}
@Override
@ -70,12 +92,21 @@ public class ConversationListFragment extends SherlockListFragment
super.onActivityCreated(bundle);
setHasOptionsMenu(true);
getListView().setAdapter(null);
getListView().addHeaderView(reminderView);
initializeListAdapter();
initializeBatchListener();
getLoaderManager().initLoader(0, null, this);
}
@Override
public void onResume() {
super.onResume();
initializeReminders();
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
@ -132,7 +163,7 @@ public class ConversationListFragment extends SherlockListFragment
}
public void resetQueryFilter() {
if (!Util.isEmpty(this.queryFilter)) {
if (!TextUtils.isEmpty(this.queryFilter)) {
setQueryFilter("");
}
}
@ -147,6 +178,7 @@ public class ConversationListFragment extends SherlockListFragment
}
return false;
}
@Override
public boolean onQueryTextChange(String newText) {
return onQueryTextSubmit(newText);
@ -170,6 +202,21 @@ public class ConversationListFragment extends SherlockListFragment
});
}
private void initializeReminders() {
final boolean isDefault = Util.isDefaultSmsProvider(getActivity());
if (isDefault) {
TextSecurePreferences.setPromptedDefaultSmsProvider(getActivity(), false);
}
if (!isDefault && !TextSecurePreferences.hasPromptedDefaultSmsProvider(getActivity())) {
showDefaultSmsReminder();
} else if (isDefault && !ApplicationMigrationService.isDatabaseImported(getActivity())) {
showSystemSmsImportReminder();
} else {
reminderView.findViewById(R.id.container).setVisibility(View.GONE);
}
}
private void initializeListAdapter() {
this.setListAdapter(new ConversationListAdapter(getActivity(), null, masterSecret));
getListView().setRecyclerListener((ConversationListAdapter)getListAdapter());
@ -292,6 +339,79 @@ public class ConversationListFragment extends SherlockListFragment
actionMode = null;
}
@TargetApi(VERSION_CODES.KITKAT)
private void showDefaultSmsReminder() {
final ViewGroup container = (ViewGroup) reminderView.findViewById(R.id.container);
setReminderData(R.drawable.sms_selection_icon,
R.string.reminder_header_sms_default_title,
R.string.reminder_header_sms_default_text,
new OnClickListener() {
@Override
public void onClick(View v) {
TextSecurePreferences.setPromptedDefaultSmsProvider(getActivity(), true);
Intent intent = new Intent(Telephony.Sms.Intents.ACTION_CHANGE_DEFAULT);
intent.putExtra(Telephony.Sms.Intents.EXTRA_PACKAGE_NAME, getActivity().getPackageName());
startActivity(intent);
}
},
new OnClickListener() {
@Override
public void onClick(View v) {
TextSecurePreferences.setPromptedDefaultSmsProvider(getActivity(), true);
container.setVisibility(View.GONE);
}
});
container.setVisibility(View.VISIBLE);
}
private void showSystemSmsImportReminder() {
final ViewGroup container = (ViewGroup) reminderView.findViewById(R.id.container);
setReminderData(R.drawable.sms_system_import_icon,
R.string.reminder_header_sms_import_title,
R.string.reminder_header_sms_import_text,
new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getActivity(), ApplicationMigrationService.class);
intent.setAction(ApplicationMigrationService.MIGRATE_DATABASE);
intent.putExtra("master_secret", masterSecret);
getActivity().startService(intent);
Intent nextIntent = new Intent(getActivity(), ConversationListActivity.class);
intent.putExtra("master_secret", masterSecret);
Intent activityIntent = new Intent(getActivity(), DatabaseMigrationActivity.class);
activityIntent.putExtra("master_secret", masterSecret);
activityIntent.putExtra("next_intent", nextIntent);
getActivity().startActivity(activityIntent);
}
},
new OnClickListener() {
@Override
public void onClick(View v) {
ApplicationMigrationService.setDatabaseImported(getActivity());
container.setVisibility(View.GONE);
}
});
container.setVisibility(View.VISIBLE);
}
private void setReminderData(int iconResId, int titleResId, int textResId, OnClickListener okListener, OnClickListener cancelListener) {
final ImageButton cancel = (ImageButton) reminderView.findViewById(R.id.cancel);
final Button ok = (Button ) reminderView.findViewById(R.id.ok);
final TextView title = (TextView ) reminderView.findViewById(R.id.reminder_title);
final TextView text = (TextView ) reminderView.findViewById(R.id.reminder_text);
final ImageView icon = (ImageView ) reminderView.findViewById(R.id.icon);
icon.setImageResource(iconResId);
title.setText(titleResId);
text.setText(textResId);
ok.setOnClickListener(okListener);
cancel.setOnClickListener(cancelListener);
}
}

View File

@ -18,10 +18,9 @@ public class RoutingActivity extends PassphraseRequiredSherlockActivity {
private static final int STATE_CREATE_PASSPHRASE = 1;
private static final int STATE_PROMPT_PASSPHRASE = 2;
private static final int STATE_IMPORT_DATABASE = 3;
private static final int STATE_CONVERSATION_OR_LIST = 4;
private static final int STATE_UPGRADE_DATABASE = 5;
private static final int STATE_PROMPT_PUSH_REGISTRATION = 6;
private static final int STATE_CONVERSATION_OR_LIST = 3;
private static final int STATE_UPGRADE_DATABASE = 4;
private static final int STATE_PROMPT_PUSH_REGISTRATION = 5;
private MasterSecret masterSecret = null;
private boolean isVisible = false;
@ -84,7 +83,6 @@ public class RoutingActivity extends PassphraseRequiredSherlockActivity {
switch (state) {
case STATE_CREATE_PASSPHRASE: handleCreatePassphrase(); break;
case STATE_PROMPT_PASSPHRASE: handlePromptPassphrase(); break;
case STATE_IMPORT_DATABASE: handleImportDatabase(); break;
case STATE_CONVERSATION_OR_LIST: handleDisplayConversationOrList(); break;
case STATE_UPGRADE_DATABASE: handleUpgradeDatabase(); break;
case STATE_PROMPT_PUSH_REGISTRATION: handlePushRegistration(); break;
@ -101,15 +99,6 @@ public class RoutingActivity extends PassphraseRequiredSherlockActivity {
startActivityForResult(intent, 2);
}
private void handleImportDatabase() {
Intent intent = new Intent(this, DatabaseMigrationActivity.class);
intent.putExtra("master_secret", masterSecret);
intent.putExtra("next_intent", getPushRegistrationIntent());
startActivity(intent);
finish();
}
private void handleUpgradeDatabase() {
Intent intent = new Intent(this, DatabaseUpgradeActivity.class);
intent.putExtra("master_secret", masterSecret);
@ -202,9 +191,6 @@ public class RoutingActivity extends PassphraseRequiredSherlockActivity {
if (masterSecret == null)
return STATE_PROMPT_PASSPHRASE;
if (!ApplicationMigrationService.isDatabaseImported(this))
return STATE_IMPORT_DATABASE;
if (DatabaseUpgradeActivity.isUpdate(this))
return STATE_UPGRADE_DATABASE;