Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.conceptualsystems.smsmobile2;
- //import android.app.Activity;
- import android.content.res.Configuration;
- import android.support.v4.app.FragmentActivity;
- import android.os.Bundle;
- import android.support.v4.app.FragmentManager;
- import android.support.v4.app.FragmentTransaction;
- import android.util.Log;
- import android.widget.LinearLayout;
- public class MainActivity extends FragmentActivity implements SmsTicketListFragment.OnTicketSelectedListener
- {
- private final FragmentManager mFM = getSupportFragmentManager();
- private Configuration mConfig;
- LinearLayout mTicketListLayout = null;
- LinearLayout mTicketReviewLayout = null;
- SmsTicketListFragment mTicketListFragment = null;
- SmsTicketReviewFragment mTicketReviewFragment = null;
- public static int TICKET_LIST_LAYOUT_ID = 1;
- public static int TICKET_REVIEW_LAYOUT_ID = 2;
- public void onTicketSelected(String selection) {
- mTicketReviewFragment = new SmsTicketReviewFragment(selection); //fm.findFragmentById(R.id.ticket_review_fragment);
- FragmentTransaction transaction = mFM.beginTransaction();
- if((mConfig.screenLayout&Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_LARGE) {
- transaction.replace(TICKET_REVIEW_LAYOUT_ID, mTicketReviewFragment);
- } else if((mConfig.screenLayout&Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_NORMAL) {
- transaction.replace(TICKET_LIST_LAYOUT_ID, mTicketReviewFragment);
- transaction.addToBackStack(null);
- }
- transaction.commit();
- //Log.i("SMSTICKET", selection);
- }
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle savedInstanceState)
- {
- super.onCreate(savedInstanceState);
- Log.i("TAG", "onCreate called");
- setContentView(R.layout.main);
- Log.i("TAG", getResources().getDisplayMetrics().toString());
- mConfig = getResources().getConfiguration();
- initScreen();
- }
- public void onStart() {
- super.onStart();
- Log.i("TAG", "onStart called");
- }
- public void onResume() {
- super.onResume();
- Log.i("TAG", "onResume called");
- }
- public void onPause() {
- super.onPause();
- Log.i("TAG", "onPause called");
- }
- public void onStop() {
- super.onStart();
- Log.i("TAG", "onStop called");
- }
- public void onConfigurationChanged(Configuration newConfig) {
- super.onConfigurationChanged(newConfig);
- mConfig = newConfig;
- initScreen();
- }
- public void initScreen() {
- switch(mConfig.screenLayout&Configuration.SCREENLAYOUT_SIZE_MASK) {
- case Configuration.SCREENLAYOUT_SIZE_SMALL:
- {
- Log.i("TAG", "Android says: small");
- }
- case Configuration.SCREENLAYOUT_SIZE_NORMAL:
- {
- Log.i("TAG", "Android says: normal / small");
- mTicketListLayout = new LinearLayout(this);
- mTicketListLayout.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT, 1f));
- mTicketListLayout.setId(TICKET_LIST_LAYOUT_ID);
- FragmentTransaction transaction = mFM.beginTransaction();
- boolean changed = false;
- if(mFM.findFragmentByTag("ticket_list_fragment") == null) {
- mTicketListFragment = new SmsTicketListFragment();
- transaction.add(TICKET_LIST_LAYOUT_ID, mTicketListFragment, "ticket_list_fragment");
- changed = true;
- }
- if(changed)
- transaction.commit();
- if(findViewById(TICKET_LIST_LAYOUT_ID) == null)
- ((LinearLayout)findViewById(R.id.root_view)).addView(mTicketListLayout);
- break;
- }
- case Configuration.SCREENLAYOUT_SIZE_LARGE:
- {
- Log.i("TAG", "Android says: large");
- mTicketListLayout = new LinearLayout(this);
- mTicketListLayout.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT, 1f));
- mTicketListLayout.setId(TICKET_LIST_LAYOUT_ID);
- mTicketReviewLayout = new LinearLayout(this);
- mTicketReviewLayout.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT, 1f));
- mTicketReviewLayout.setId(TICKET_REVIEW_LAYOUT_ID);
- FragmentTransaction transaction = mFM.beginTransaction();
- boolean changed=false;
- if(mFM.findFragmentByTag("ticket_list_fragment") == null) {
- mTicketListFragment = new SmsTicketListFragment();
- transaction.add(TICKET_LIST_LAYOUT_ID, mTicketListFragment, "ticket_list_fragment");
- changed = true;
- }
- if(mFM.findFragmentByTag("ticket_review_fragment") == null) {
- mTicketReviewFragment = new SmsTicketReviewFragment();
- transaction.add(TICKET_REVIEW_LAYOUT_ID, mTicketReviewFragment, "ticket_review_fragment");
- changed = true;
- }
- if(changed)
- transaction.commit();
- if(mConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
- ((LinearLayout)findViewById(R.id.root_view)).setOrientation(LinearLayout.HORIZONTAL);
- } else if(mConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
- ((LinearLayout)findViewById(R.id.root_view)).setOrientation(LinearLayout.VERTICAL);
- }
- if(findViewById(TICKET_LIST_LAYOUT_ID) == null)
- ((LinearLayout)findViewById(R.id.root_view)).addView(mTicketListLayout);
- if(findViewById(TICKET_REVIEW_LAYOUT_ID) == null)
- ((LinearLayout)findViewById(R.id.root_view)).addView(mTicketReviewLayout);
- break;
- }
- /***** not supported? *****
- case Configuration.SCREENLAYOUT_SIZE_XLARGE:
- Log.i("TAG", "Android says: xlarge");
- break;
- */
- }
- //set the screen according to screen layout and orientation
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement