Commit 0b16eea7 authored by Alexandre Lision's avatar Alexandre Lision Committed by gerrit2
Browse files

rotation: allow landscape in all app

This commit bring auto-rotation for all the screens, according
to user settings (screen rotation locked/unlocked).

It was previously reserved to the CallActivity.
- clean styles.xml
- remove dead code (SettingsActivity)
- layout ajustement across the app to manage toolbars manually
(toolbar title is layouted in the bottom for the AccountManagementFragment)

Tuleap: #727
Change-Id: I0e46ea8afcb88d99627090eb0c33f4ea24f4825c
parent a5d953c9
......@@ -66,9 +66,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<uses-feature
android:name="android.hardware.bluetooth"
android:required="false" />
<uses-feature
android:name="android.hardware.screen.portrait"
android:required="false" />
<application
android:allowBackup="true"
......@@ -78,10 +75,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<activity
android:name=".client.HomeActivity"
android:label="@string/title_activity_sflphone_home"
android:screenOrientation="portrait"
android:theme="@style/AppThemeWithOverlay"
android:theme="@style/AppThemeBase"
android:windowSoftInputMode="adjustResize"
android:launchMode="singleTask">
android:screenOrientation="fullUser"
android:launchMode="singleTask"
android:configChanges="orientation|screenSize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
......@@ -143,8 +141,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
</activity>
<activity
android:name=".client.AccountWizard"
android:screenOrientation="portrait"
android:theme="@style/AppThemeWithoutOverlayCompat">
android:theme="@style/AppThemeBase"
android:screenOrientation="fullUser"
android:configChanges="orientation|screenSize">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="cx.ring.client.AccountEditionActivity" />
......@@ -152,12 +151,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<activity
android:name=".client.AccountEditionActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:theme="@style/AppThemeWithoutOverlayCompatNoShadow" />
android:theme="@style/AppThemeBase"
android:screenOrientation="fullUser"
android:configChanges="orientation|screenSize"/>
<activity
android:name=".client.NewConversationActivity"
android:label="@string/app_name"
android:theme="@style/AppThemeWithoutOverlay" />
android:theme="@style/AppThemeBase"
android:screenOrientation="fullUser"/>
<receiver android:name=".service.OutgoingCallHandler">
<intent-filter>
......@@ -175,7 +176,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<activity
android:name=".client.CallActivity"
android:label="@string/app_name"
android:screenOrientation="fullSensor"
android:screenOrientation="fullUser"
android:configChanges="orientation|screenSize"
android:theme="@style/AppTheme.ActionBar.Transparent"
android:windowSoftInputMode="adjustPan|stateHidden">
......@@ -242,21 +243,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
android:name=".client.ConversationActivity"
android:label="@string/app_name"
android:parentActivityName=".client.HomeActivity"
android:screenOrientation="portrait"
android:theme="@style/AppThemeWithoutOverlayCompat"
android:windowSoftInputMode="adjustResize" />
<activity
android:name=".client.SettingsActivity"
android:label="@string/menu_item_settings"
android:theme="@style/AppThemeWithoutOverlayCompat">
<intent-filter>
<action android:name="android.intent.action.MANAGE_NETWORK_USAGE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
android:theme="@style/AppThemeBase"
android:windowSoftInputMode="adjustResize"
android:screenOrientation="fullUser"/>
<activity android:name=".client.QRCodeScannerActivity"
android:screenOrientation="fullSensor"
android:screenOrientation="fullUser"
android:stateNotNeeded="true"
android:theme="@style/zxing_CaptureTheme"
android:windowSoftInputMode="stateAlwaysHidden">
......
......@@ -46,8 +46,8 @@ import android.support.v13.app.FragmentPagerAdapter;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v4.view.ViewPager;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.util.Pair;
import android.view.KeyEvent;
......@@ -144,9 +144,9 @@ public class AccountEditionActivity extends AppCompatActivity implements LocalSe
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_account_settings);
final ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setElevation(0);
Toolbar toolbar = (Toolbar) findViewById(R.id.main_toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
if (!mBound) {
Intent intent = new Intent(this, LocalService.class);
......@@ -164,6 +164,7 @@ public class AccountEditionActivity extends AppCompatActivity implements LocalSe
@Override
protected void onDestroy() {
super.onDestroy();
if (mBound) {
unbindService(mConnection);
mBound = false;
......@@ -172,14 +173,13 @@ public class AccountEditionActivity extends AppCompatActivity implements LocalSe
@Override
public boolean onOptionsItemSelected(MenuItem item) {
AlertDialog dialog;
switch (item.getItemId()) {
case android.R.id.home:
finish();
return true;
case R.id.menuitem_delete:
dialog = createDeleteDialog();
dialog.show();
AlertDialog deleteDialog = createDeleteDialog();
deleteDialog.show();
break;
case R.id.menuitem_export:
startExport();
......@@ -352,6 +352,7 @@ public class AccountEditionActivity extends AppCompatActivity implements LocalSe
if (!checkPassword(pwd, pwd_confirm)) {
final String pwd_txt = pwd.getText().toString();
alertDialog.dismiss();
new ExportAccountTask().execute(pwd_txt);
}
}
......@@ -382,15 +383,15 @@ public class AccountEditionActivity extends AppCompatActivity implements LocalSe
}
private class ExportAccountTask extends AsyncTask<String, Void, Integer> {
private ProgressDialog loading_dialog = null;
ProgressDialog exportDialog;
private String path;
@Override
protected void onPreExecute() {
loading_dialog = ProgressDialog.show(AccountEditionActivity.this,
exportDialog = ProgressDialog.show(AccountEditionActivity.this,
getString(R.string.export_dialog_title),
getString(R.string.import_export_wait), true);
loading_dialog.setCancelable(false);
exportDialog.setCancelable(false);
}
protected Integer doInBackground(String... args) {
......@@ -408,11 +409,13 @@ public class AccountEditionActivity extends AppCompatActivity implements LocalSe
}
protected void onPostExecute(Integer ret) {
if (loading_dialog != null)
loading_dialog.dismiss();
if (exportDialog != null){
exportDialog.dismiss();
}
Log.d(TAG, "Account export to " + path + " returned " + ret);
if (ret == 0) {
Snackbar.make(findViewById(android.R.id.content), getString(R.string.account_export_result, path), Snackbar.LENGTH_INDEFINITE).show();
Snackbar.make(findViewById(android.R.id.content), getString(R.string.account_export_result, path), Snackbar.LENGTH_LONG).show();
} else
new AlertDialog.Builder(AccountEditionActivity.this).setTitle(R.string.export_failed_dialog_title)
.setMessage(R.string.export_failed_dialog_msg)
......
......@@ -27,21 +27,23 @@ import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.MenuItem;
import java.util.ArrayList;
import java.util.Locale;
import cx.ring.R;
import cx.ring.fragments.AccountCreationFragment;
import cx.ring.service.IDRingService;
import cx.ring.service.LocalService;
import java.util.ArrayList;
import java.util.Locale;
public class AccountWizard extends AppCompatActivity implements LocalService.Callbacks {
static final String TAG = "AccountWizard";
private boolean mBound = false;
......@@ -65,8 +67,10 @@ public class AccountWizard extends AppCompatActivity implements LocalService.Cal
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_wizard);
Toolbar toolbar = (Toolbar) findViewById(R.id.main_toolbar);
setSupportActionBar(toolbar);
mViewPager = (ViewPager) findViewById(R.id.pager);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
......
......@@ -95,6 +95,7 @@ public class CallActivity extends AppCompatActivity implements Callbacks, CallFr
}
setContentView(R.layout.activity_call_layout);
mMainView = findViewById(R.id.maincalllayout);
mMainView.setOnClickListener(new View.OnClickListener() {
@Override
......@@ -134,7 +135,6 @@ public class CallActivity extends AppCompatActivity implements Callbacks, CallFr
showSystemUI();
}
//hideSystemUI();
super.onConfigurationChanged(newConfig);
}
......
......@@ -34,10 +34,12 @@ import android.os.IBinder;
import android.os.SystemClock;
import android.support.design.widget.Snackbar;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.util.Pair;
import android.view.KeyEvent;
......@@ -68,6 +70,7 @@ public class ConversationActivity extends AppCompatActivity implements
Conversation.ConversationActionCallback,
ClipboardHelper.ClipboardHelperCallback {
private static final String TAG = ConversationActivity.class.getSimpleName();
private static final String CONVERSATION_DELETE = "CONVERSATION_DELETE";
public static final Uri CONTENT_URI = Uri.withAppendedPath(LocalService.AUTHORITY_URI,
"conversations");
......@@ -76,6 +79,8 @@ public class ConversationActivity extends AppCompatActivity implements
private boolean mBound = false;
private boolean mVisible = false;
private AlertDialog mDeleteDialog;
private boolean mDeleteConversation = false;
private LocalService mService = null;
private Conversation mConversation = null;
......@@ -212,6 +217,11 @@ public class ConversationActivity extends AppCompatActivity implements
mConversation.mVisible = true;
mService.readConversation(mConversation);
}
if (mDeleteConversation) {
mDeleteDialog = Conversation.launchDeleteAction(ConversationActivity.this, mConversation, ConversationActivity.this);
}
mRefreshTaskHandler.postDelayed(refreshTask, REFRESH_INTERVAL_MS);
}
......@@ -254,7 +264,12 @@ public class ConversationActivity extends AppCompatActivity implements
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.frag_conversation);
setContentView(R.layout.activity_conversation);
Toolbar toolbar = (Toolbar) findViewById(R.id.main_toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
mMsgEditTxt = (EditText) findViewById(R.id.msg_input_txt);
mMsgEditTxt.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
......@@ -302,6 +317,9 @@ public class ConversationActivity extends AppCompatActivity implements
mNumberSpinner = (Spinner) findViewById(R.id.number_selector);
// reload delete conversation state (before rotation)
mDeleteConversation = savedInstanceState!=null && savedInstanceState.getBoolean(CONVERSATION_DELETE);
if (!mBound) {
Log.d(TAG, "onCreate: Binding service...");
Intent intent = new Intent(this, LocalService.class);
......@@ -351,13 +369,28 @@ public class ConversationActivity extends AppCompatActivity implements
unbindService(mConnection);
mBound = false;
}
if (mDeleteConversation) {
mDeleteDialog.dismiss();
}
super.onDestroy();
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
// persist the delete popup state in case of Activity rotation
mDeleteConversation = mDeleteDialog!=null && mDeleteDialog.isShowing();
outState.putBoolean(CONVERSATION_DELETE, mDeleteConversation);
}
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
if (mAddContactBtn != null)
if (mAddContactBtn != null) {
mAddContactBtn.setVisible(mConversation != null && mConversation.getContact().getId() < 0);
}
return super.onPrepareOptionsMenu(menu);
}
......@@ -372,6 +405,9 @@ public class ConversationActivity extends AppCompatActivity implements
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
finish();
return true;
case R.id.conv_action_audiocall:
onCallWithVideo(false);
return true;
......@@ -382,7 +418,7 @@ public class ConversationActivity extends AppCompatActivity implements
startActivityForResult(mConversation.contact.getAddNumberIntent(), REQ_ADD_CONTACT);
return true;
case R.id.menuitem_delete:
Conversation.launchDeleteAction(this, this.mConversation, this);
mDeleteDialog = Conversation.launchDeleteAction(this, this.mConversation, this);
return true;
case R.id.menuitem_copy_content:
Conversation.launchCopyNumberToClipboardFromContact(this,
......
......@@ -49,6 +49,7 @@ import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.text.Layout;
import android.transition.Explode;
import android.transition.Fade;
import android.util.Log;
......@@ -58,6 +59,8 @@ import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.WriterException;
......@@ -103,7 +106,9 @@ public class HomeActivity extends AppCompatActivity implements LocalService.Call
private MenuHeaderView fMenuHead = null;
private DrawerLayout mNavigationDrawer;
private ActionBarDrawerToggle mDrawerToggle;
private Toolbar toolbar;
private Toolbar mToolbar;
private LinearLayout mToolbarSpacerView;
private TextView mToolbarSpacerTitle;
private float mToolbarSize;
private FloatingActionButton actionButton;
protected android.app.Fragment fContent;
......@@ -140,10 +145,13 @@ public class HomeActivity extends AppCompatActivity implements LocalService.Call
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
toolbar = (Toolbar) findViewById(R.id.main_toolbar);
setSupportActionBar(toolbar);
mToolbar = (Toolbar) findViewById(R.id.main_toolbar);
setSupportActionBar(mToolbar);
actionButton = (FloatingActionButton) findViewById(R.id.action_button);
mToolbarSpacerView = (LinearLayout)findViewById(R.id.toolbar_spacer);
mToolbarSpacerTitle = (TextView)findViewById(R.id.toolbar_spacer_title);
fMenu = (NavigationView) findViewById(R.id.left_drawer);
fMenu.setNavigationItemSelectedListener(this);
mNavigationDrawer = (DrawerLayout) findViewById(R.id.drawer_layout);
......@@ -311,17 +319,29 @@ public class HomeActivity extends AppCompatActivity implements LocalService.Call
}
public void setToolbarState(boolean double_h, int title_res) {
ViewGroup.LayoutParams params = toolbar.getLayoutParams();
mToolbar.setMinimumHeight((int) mToolbarSize);
ViewGroup.LayoutParams toolbarSpacerViewParams = mToolbarSpacerView.getLayoutParams();
if (double_h) {
params.height = (int) (mToolbarSize * 2);
// setting the height of the toolbar spacer with the same height than the toolbar
toolbarSpacerViewParams.height = (int)mToolbarSize;
mToolbarSpacerView.setLayoutParams(toolbarSpacerViewParams);
// setting the toolbar spacer title (hiding the real toolbar title)
mToolbarSpacerTitle.setText(title_res);
mToolbar.setTitle("");
// the spacer and the action button become visible
mToolbarSpacerView.setVisibility(View.VISIBLE);
actionButton.setVisibility(View.VISIBLE);
} else {
params.height = (int) mToolbarSize;
// hide the toolbar spacer and the action button
mToolbarSpacerView.setVisibility(View.GONE);
actionButton.setVisibility(View.GONE);
mToolbar.setTitle(title_res);
}
toolbar.setLayoutParams(params);
toolbar.setMinimumHeight((int) mToolbarSize);
toolbar.setTitle(title_res);
}
public FloatingActionButton getActionButton() {
......
package cx.ring.client;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.MenuItem;
import cx.ring.fragments.SettingsFragment;
public class SettingsActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getFragmentManager().beginTransaction()
.replace(android.R.id.content, new SettingsFragment())
.commit();
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
finish();
return true;
}
return super.onOptionsItemSelected(item);
}
}
......@@ -52,6 +52,7 @@ import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
......@@ -77,6 +78,7 @@ public class SmartListFragment extends Fragment implements SearchView.OnQueryTex
private static final String TAG = SmartListFragment.class.getSimpleName();
private static final int USER_INPUT_DELAY = 300;
private static final String STATE_LOADING = TAG + ".STATE_LOADING";
private LocalService.Callbacks mCallbacks = LocalService.DUMMY_CALLBACKS;
private SmartListAdapter mSmartListAdapter;
......@@ -88,7 +90,7 @@ public class SmartListFragment extends Fragment implements SearchView.OnQueryTex
private MenuItem mDialpadMenuItem = null;
private ListView mList = null;
private View mLoader = null;
private ProgressBar mLoader = null;
private TextView mEmptyTextView = null;
private ViewGroup mNewContact;
......@@ -250,6 +252,16 @@ public class SmartListFragment extends Fragment implements SearchView.OnQueryTex
return true;
}
@Override
public void onSaveInstanceState(Bundle outState) {
if (null != mLoader) {
// if there's another fragment on top of this one, when a rotation is done, this fragment is destroyed and
// in the process of recreating it, as it is not shown on the top of the screen, the "onCreateView" method is never called, so the mLoader is null
outState.putBoolean(STATE_LOADING, mLoader.isShown());
}
super.onSaveInstanceState(outState);
}
@Override
public boolean onQueryTextChange(final String query) {
if (TextUtils.isEmpty(query)) {
......@@ -302,8 +314,11 @@ public class SmartListFragment extends Fragment implements SearchView.OnQueryTex
mList.setOnItemLongClickListener(conversationLongClickListener);
this.mEmptyTextView = (TextView) inflatedView.findViewById(R.id.emptyTextView);
this.mLoader = inflatedView.findViewById(android.R.id.empty);
this.setLoading(true);
this.mLoader = (ProgressBar) inflatedView.findViewById(R.id.loading_indicator);
if (savedInstanceState != null) {
this.setLoading(savedInstanceState.getBoolean(STATE_LOADING, false));
}
mNewContact = (ViewGroup) inflatedView.findViewById(R.id.newcontact_element);
mNewContact.setVisibility(View.GONE);
......
......@@ -267,17 +267,17 @@ public class Conversation extends ContentObservable {
void copyContactNumberToClipboard(String contactNumber);
}
public static void launchDeleteAction(final Activity activity,
public static AlertDialog launchDeleteAction(final Activity activity,
final Conversation conversation,
final ConversationActionCallback callback) {
if (activity == null) {
Log.d(TAG, "launchDeleteAction: activity is null");
return;
return null;
}
if (conversation == null) {
Log.d(TAG, "launchDeleteAction: conversation is null");
return;
return null;
}
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
......@@ -300,6 +300,7 @@ public class Conversation extends ContentObservable {
AlertDialog alertDialog = builder.create();
alertDialog.show();
return alertDialog;
}
public static void presentActions(final Activity activity,
......
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
tools:context=".client.AccountEditionActivity">
<com.astuetz.PagerSlidingTabStrip
android:id="@+id/sliding_tabs"
<LinearLayout
android:id="@+id/header_container"
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:background="@color/color_primary_light"
android:orientation="vertical"
android:elevation="4dp"
android:textColor="@color/text_color_primary_dark"
app:pstsUnderlineHeight="0dp"
app:pstsShouldExpand="true"
app:paddingStart="20dp"
app:pstsIndicatorHeight="2dp"
app:pstsIndicatorColor="@android:color/white"
app:pstsDividerColor="@android:color/transparent"/>
app:elevation="4dp">
<android.support.v7.widget.Toolbar
android:id="@+id/main_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:popupTheme="@style/Theme.AppCompat.Light.NoActionBar"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:titleTextAppearance="@style/ToolbarTitle"
app:contentInsetStart="72dp"
app:titleTextAppearance="@style/ToolbarTitle" />
<com.astuetz.PagerSlidingTabStrip
android:id="@+id/sliding_tabs"
android:layout_width="match_parent"
android:layout_height="48dp"