Example usage for android.widget TabHost newTabSpec

List of usage examples for android.widget TabHost newTabSpec

Introduction

In this page you can find the example usage for android.widget TabHost newTabSpec.

Prototype

@NonNull
public TabSpec newTabSpec(@NonNull String tag) 

Source Link

Document

Creates a new TabSpec associated with this tab host.

Usage

From source file:fr.mixit.android.ui.StarredActivity.java

/** Build and add "sessions" tab. */
private void setupSessionsTab() {
    final TabHost host = getTabHost();

    final Uri uri = MixItContract.Sessions.CONTENT_STARRED_URI.buildUpon()
            .appendQueryParameter(MixItContract.SessionCounts.SESSION_INDEX_EXTRAS, Boolean.TRUE.toString())
            .build();//from   www .j  a v  a  2  s .c  o m
    final Intent intent = new Intent(Intent.ACTION_VIEW, uri);
    intent.addCategory(Intent.CATEGORY_TAB);
    final boolean highlightParalleStarred = settingsPrefs
            .getBoolean(getString(R.string.visualize_parallel_starred_sessions_key), false);
    intent.putExtra(SessionsActivity.EXTRA_HIHGLIGHT_PARALLEL_STARRED, highlightParalleStarred);
    intent.putExtra(SessionsActivity.EXTRA_FOCUS_CURRENT_NEXT_SESSION, true);

    // Sessions content comes from reused activity
    host.addTab(host.newTabSpec(TAG_SESSIONS).setIndicator(buildIndicator(R.string.starred_sessions))
            .setContent(intent));
}

From source file:com.tutor.fragment.ViewPageFragment.java

private boolean initialjfTabHostFromWeb(LayoutInflater inflater, View mView) {
    List<FDItemTyeModel> jfItems = GetjfItems();
    if (jfItems == null || jfItems.size() == 0) {
        return false;
    }/*from w w w .  j a  v a2 s  .  co  m*/
    final TabHost tabHost = (TabHost) mView.findViewById(R.id.jf_tabhost);
    tabHost.setup();
    View tabItem = inflater.inflate(R.layout.tab_fd_widebg, null);
    TextView tbTabItemTitle = (TextView) tabItem.findViewById(R.id.tvTabItemTitle);
    for (int i = 0; i < 3; i++) {

        if (i == 2) {
            tabItem = inflater.inflate(R.layout.tab_fd_widebg, null);
            tbTabItemTitle = (TextView) tabItem.findViewById(R.id.tvTabItemTitle);
            tbTabItemTitle.setText("");
            tabHost.addTab(tabHost.newTabSpec("-1").setIndicator(tabItem).setContent(R.id.tab3));
            setJFListViewAdapter(tabHost);
            break;
        }
        switch (i) {
        case 0:
            InitialJfItemInf(jfItems.get(i).getItem_ID());
            tbTabItemTitle.setText(jfItems.get(i).getItem_Name());
            tabHost.addTab(tabHost.newTabSpec(jfItems.get(i).getItem_Name()).setIndicator(tabItem)
                    .setContent(R.id.tab1));
            break;
        case 1:
            tabItem = inflater.inflate(R.layout.tab_fd_widebg, null);
            tbTabItemTitle = (TextView) tabItem.findViewById(R.id.tvTabItemTitle);
            tbTabItemTitle.setText(jfItems.get(i).getItem_Name());
            tabHost.addTab(tabHost.newTabSpec(jfItems.get(i).getItem_Name()).setIndicator(tabItem)
                    .setContent(R.id.tab2));
            break;
        }
    }

    tabHost.setOnTabChangedListener(new OnTabChangeListener() {
        @Override
        public void onTabChanged(String tabId) {
            if (tabId != "-1") {
                int itemId = Integer.parseInt(jfTypesMap.get(tabId.toString()).toString());
                InitialJfItemInf(itemId);
                setJFListViewAdapter(tabHost);
            } else {
                tabHost.setCurrentTab(0);
                Intent intent = new Intent(getActivity(), MoreActivity.class);

                intent.putExtra("Flag", "jf");
                startActivity(intent);
            }
        }
    });

    return true;
}

From source file:no.ntnu.idi.socialhitchhiking.map.MapActivityAddPickupAndDropoff.java

@Override
protected void onCreate(Bundle icicle) {
    super.onCreate(icicle);

    // Getting the selected journey
    Journey journey = getApp().getSelectedJourney();

    // Setting up tabs
    TabHost tabs = (TabHost) findViewById(R.id.tabhost);
    tabs.setup();/*from www  .  j a v a  2s  .co m*/

    // Adding Ride tab
    TabHost.TabSpec specRide = tabs.newTabSpec("tag1");
    specRide.setContent(R.id.ride_tab);
    specRide.setIndicator("Ride");
    tabs.addTab(specRide);

    // Adding Driver tab
    TabHost.TabSpec specDriver = tabs.newTabSpec("tag2");
    specDriver.setContent(R.id.driver_tab);
    specDriver.setIndicator("Driver");
    tabs.addTab(specDriver);

    // Adding the pickup location address text
    ((AutoCompleteTextView) findViewById(R.id.pickupText))
            .setText(getIntent().getExtras().getString("pickupString"));

    // Adding the dropoff location address text
    ((AutoCompleteTextView) findViewById(R.id.dropoffText))
            .setText(getIntent().getExtras().getString("dropoffString"));

    // Drawing the pickup and dropoff locations on the map
    setPickupLocation();
    setDropOffLocation();

    // Adding image of the driver
    User driver = journey.getRoute().getOwner();
    picture = (ImageView) findViewById(R.id.mapViewPickupImage);

    // Create an object for subclass of AsyncTask
    GetImage task = new GetImage(picture, this);
    // Execute the task: Get image from url and add it to the ImageView
    task.execute(driver.getPictureURL());

    // Adding the name of the driver
    ((TextView) findViewById(R.id.mapViewPickupTextViewName)).setText(driver.getFullName());

    // Getting the drivers preferences for this ride
    TripPreferences pref = journey.getTripPreferences();

    // Setting the smoking preference
    if (pref.getSmoking()) {
        ((ImageView) findViewById(R.id.mapViewPickupImageViewSmokingIcon))
                .setImageResource(R.drawable.green_check);
    } else {
        ((ImageView) findViewById(R.id.mapViewPickupImageViewSmokingIcon))
                .setImageResource(R.drawable.red_cross);
    }
    // Setting the animals preference
    if (pref.getAnimals()) {
        ((ImageView) findViewById(R.id.mapViewPickupImageViewAnimalsIcon))
                .setImageResource(R.drawable.green_check);
    } else {
        ((ImageView) findViewById(R.id.mapViewPickupImageViewAnimalsIcon))
                .setImageResource(R.drawable.red_cross);
    }
    // Setting the breaks preference
    if (pref.getBreaks()) {
        ((ImageView) findViewById(R.id.mapViewPickupImageViewBreaksIcon))
                .setImageResource(R.drawable.green_check);
    } else {
        ((ImageView) findViewById(R.id.mapViewPickupImageViewBreaksIcon))
                .setImageResource(R.drawable.red_cross);
    }
    // Setting the music preference
    if (pref.getMusic()) {
        ((ImageView) findViewById(R.id.mapViewPickupImageViewMusicIcon))
                .setImageResource(R.drawable.green_check);
    } else {
        ((ImageView) findViewById(R.id.mapViewPickupImageViewMusicIcon)).setImageResource(R.drawable.red_cross);
    }
    // Setting the talking preference
    if (pref.getTalking()) {
        ((ImageView) findViewById(R.id.mapViewPickupImageViewTalkingIcon))
                .setImageResource(R.drawable.green_check);
    } else {
        ((ImageView) findViewById(R.id.mapViewPickupImageViewTalkingIcon))
                .setImageResource(R.drawable.red_cross);
    }

    // Setting the number of available seats
    ((TextView) findViewById(R.id.mapViewPickupTextViewSeats))
            .setText(pref.getSeatsAvailable() + " available seats");

    // Setting the age of the driver
    ((TextView) findViewById(R.id.mapViewPickupTextViewAge)).setText("Age: " + driver.getAge());

    // Adding the gender of the driver
    if (driver.getGender() != null) {
        if (driver.getGender().equals("m")) {
            ((ImageView) findViewById(R.id.mapViewPickupImageViewGender)).setImageResource(R.drawable.male);
        } else if (driver.getGender().equals("f")) {
            ((ImageView) findViewById(R.id.mapViewPickupImageViewGender)).setImageResource(R.drawable.female);
        }
    }

    // Addring the rating of the driver
    ((TextView) findViewById(R.id.recommendations)).setText("Recommendations: " + (int) driver.getRating());

    // Setting the drivers mobile number
    ((TextView) findViewById(R.id.mapViewPickupTextViewPhone)).setText("Mobile: " + driver.getPhone());

    try {
        // Getting the car image
        Car dummyCar = new Car(driver.getCarId(), "Dummy", 0.0); //"Dummy" and 0.0 are dummy vars. getApp() etc sends the current user's carid
        Request carReq = new CarRequest(RequestType.GET_CAR, getApp().getUser(), dummyCar);
        CarResponse carRes = (CarResponse) RequestTask.sendRequest(carReq, getApp());
        Car car = carRes.getCar();
        Bitmap carImage = BitmapFactory.decodeByteArray(car.getPhoto(), 0, car.getPhoto().length);

        // Setting the car image
        ((ImageView) findViewById(R.id.mapViewPickupImageViewCar)).setImageBitmap(carImage);

        // Setting the car name
        ((TextView) findViewById(R.id.mapViewPickupTextViewCarName)).setText("Car type: " + car.getCarName());

        // Setting the comfort
        ((RatingBar) findViewById(R.id.mapViewPickupAndDropoffComfortStars))
                .setRating((float) car.getComfort());

    } catch (ClientProtocolException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    } catch (IOException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    } catch (InterruptedException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    } catch (ExecutionException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }

    // Adding the date of ride
    Date d = journey.getStart().getTime();
    SimpleDateFormat sdfDate = new SimpleDateFormat("MMM dd yyyy");
    SimpleDateFormat sdfTime = new SimpleDateFormat("HH:mm zzz");
    String dateText = "Date: " + sdfDate.format(d);
    String timeText = "Time: " + sdfTime.format(d);
    ((TextView) findViewById(R.id.mapViewPickupTextViewDate)).setText(dateText + "\n" + timeText);

    //Adding Gender to the driver
    ImageView iv_image;
    iv_image = (ImageView) findViewById(R.id.gender);

    try {
        if (driver.getGender().equals("Male")) {
            Drawable male = getResources().getDrawable(R.drawable.male);
            iv_image.setImageDrawable(male);
        } else if (driver.getGender().equals("Female")) {
            Drawable female = getResources().getDrawable(R.drawable.female);
            iv_image.setImageDrawable(female);
        }
    } catch (NullPointerException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }

    // Initializing the two autocomplete textviews pickup and dropoff
    initAutocomplete();

    // Adding onClickListener for the button "Ask for a ride"
    btnSendRequest = (Button) findViewById(no.ntnu.idi.socialhitchhiking.R.id.mapViewPickupBtnSendRequest);
    btnSendRequest.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            Response res;
            NotificationRequest req;

            if (pickupPoint == null || dropoffPoint == null) {
                //makeToast("You have to choose pickup point and dropoff point.");
                AlertDialog.Builder ad = new AlertDialog.Builder(MapActivityAddPickupAndDropoff.this);
                ad.setMessage("You have to choose pickup point and dropoff point.");
                ad.setTitle("Unable to send request");
                ad.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {

                    }
                });
                ad.show();
                return;
            }

            inPickupMode = true;

            String senderID = getApp().getUser().getID();
            String recipientID = getApp().getSelectedJourney().getRoute().getOwner().getID();
            String senderName = getApp().getUser().getFullName();
            String comment = ((EditText) findViewById(R.id.mapViewPickupEtComment)).getText().toString();
            int journeyID = getApp().getSelectedJourney().getSerial();

            // Creating a new notification to be sendt to the driver
            Notification n = new Notification(senderID, recipientID, senderName, comment, journeyID,
                    NotificationType.HITCHHIKER_REQUEST, pickupPoint, dropoffPoint, Calendar.getInstance());
            req = new NotificationRequest(RequestType.SEND_NOTIFICATION, getApp().getUser(), n);

            // Sending notification
            try {
                res = RequestTask.sendRequest(req, getApp());
                if (res instanceof UserResponse) {
                    if (res.getStatus() == ResponseStatus.OK) {
                        makeToast("Ride request sent to driver");
                        finish();
                    }
                    if (res.getStatus() == ResponseStatus.FAILED) {
                        if (res.getErrorMessage().contains("no_duplicate_notifications")) {
                            //makeToast("You have already sent a request on this journey");
                            AlertDialog.Builder ad = new AlertDialog.Builder(
                                    MapActivityAddPickupAndDropoff.this);
                            ad.setMessage("You have already sent a request on this ride");
                            ad.setTitle("Unable to send request");
                            ad.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int id) {

                                }
                            });
                            ad.show();
                        } else if (res.getErrorMessage().equals("No available seats")) {
                            //makeToast("There are no available seats on this ride");
                            AlertDialog.Builder ad = new AlertDialog.Builder(
                                    MapActivityAddPickupAndDropoff.this);
                            ad.setMessage("There are no available seats on this ride");
                            ad.setTitle("Unable to send request");
                            ad.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int id) {

                                }
                            });
                            ad.show();
                        } else if (res.getErrorMessage().equals("User already in journey")) {
                            //makeToast("You have already hitched this ride");
                            AlertDialog.Builder ad = new AlertDialog.Builder(
                                    MapActivityAddPickupAndDropoff.this);
                            ad.setMessage("You have already hitched this ride");
                            ad.setTitle("Unable to send request");
                            ad.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int id) {

                                }
                            });
                            ad.show();
                        } else {
                            makeToast("Could not send request");
                        }
                    }
                }
            } catch (ClientProtocolException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (ExecutionException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        }
    });

    // Adding buttons where you choose between pickup point and dropoff point
    btnSelectPickupPoint = (Button) findViewById(R.id.mapViewPickupBtnPickup);
    btnSelectPickupPoint.setBackgroundColor(notSelected);
    btnSelectDropoffPoint = (Button) findViewById(R.id.mapViewPickupBtnDropoff);
    btnSelectDropoffPoint.setBackgroundColor(notSelected);
    // Setting the selected pickup point
    btnSelectPickupPoint.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View arg0) {
            isSelectingDropoffPoint = false;
            isSelectingPickupPoint = true;
            btnSelectPickupPoint.setBackgroundColor(selected);
            btnSelectDropoffPoint.setBackgroundColor(notSelected);
            makeToast("Press the map to add pickup location");

        }
    });

    // Setting the selected dropoff point
    btnSelectDropoffPoint.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View arg0) {
            isSelectingDropoffPoint = true;
            isSelectingPickupPoint = false;
            btnSelectPickupPoint.setBackgroundColor(notSelected);
            btnSelectDropoffPoint.setBackgroundColor(selected);
            makeToast("Press the map to add dropoff location");
        }
    });

    // Adding message to the user
    makeToast("Please set a pickup and dropoff location.");
}

From source file:com.github.colorchief.colorchief.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);

    final TabHost tabHost = (TabHost) findViewById(R.id.tabHost);
    tabHost.setup();//w w  w. ja  v  a  2 s.  c om

    final TabHost.TabSpec tabImageView = tabHost.newTabSpec("Image View");
    final TabHost.TabSpec tabSettings = tabHost.newTabSpec("Settings");
    final TabHost.TabSpec tabAbout = tabHost.newTabSpec("About");

    tabImageView.setIndicator("", ContextCompat.getDrawable(this, R.drawable.ic_action_picture));
    tabImageView.setContent(R.id.tabImageView);

    tabSettings.setIndicator("", ContextCompat.getDrawable(this, R.drawable.ic_action_gear));
    tabSettings.setContent(R.id.tabSettings);

    tabAbout.setIndicator("", ContextCompat.getDrawable(this, R.drawable.ic_action_help));
    tabAbout.setContent(R.id.tabAbout);

    /** Add the tabs  to the TabHost to display. */
    tabHost.addTab(tabImageView);
    tabHost.addTab(tabSettings);
    tabHost.addTab(tabAbout);

    colorLUT.initLUT(LUT_SIZE, LUT_SIZE, LUT_SIZE);

    //check savedInstance
    // for Tab state and set active tab accordingly
    // for LUT values and update (restore) accordingly
    if (savedInstanceState != null) {
        tabHost.setCurrentTab(savedInstanceState.getInt("Active Tab"));
        colorLUT.setColorLutArray(savedInstanceState.getIntArray("Color LUT"));
    }

    ((SeekBar) findViewById(R.id.seekBarChromaPowerFactor)).setMax(POWER_FACTOR_SEEK_BAR_MAX);
    ((SeekBar) findViewById(R.id.seekBarChromaPowerFactor)).setProgress(getSeekPosition(powerFactor));

    if (Lselect == LutCalculate.L_SELECT_IN) {
        ((RadioButton) findViewById(R.id.radioButtonLin)).setChecked(true);
        ((RadioButton) findViewById(R.id.radioButtonLout)).setChecked(false);
    } else if (Lselect == LutCalculate.L_SELECT_OUT) {
        ((RadioButton) findViewById(R.id.radioButtonLin)).setChecked(false);
        ((RadioButton) findViewById(R.id.radioButtonLout)).setChecked(true);
    }
    if (Cselect == LutCalculate.C_SELECT_ABSOLUTE) {
        ((RadioButton) findViewById(R.id.radioButtonCin)).setChecked(true);
        ((RadioButton) findViewById(R.id.radioButtonCrelative)).setChecked(false);
        ((SeekBar) findViewById(R.id.seekBarChromaPowerFactor)).setEnabled(false);

    } else if (Cselect == LutCalculate.C_SELECT_RELATIVE) {
        ((RadioButton) findViewById(R.id.radioButtonCin)).setChecked(false);
        ((RadioButton) findViewById(R.id.radioButtonCrelative)).setChecked(true);
        ((SeekBar) findViewById(R.id.seekBarChromaPowerFactor)).setEnabled(true);
    }

    if (uriIccProfileIn != null)
        iccProfileIn.loadFromFile(uriIccProfileIn);
    if (uriIccProfileOut != null)
        iccProfileOut.loadFromFile(uriIccProfileOut);

    if (bitmapLoaded) {

        transformImage();
        updateImageViewer();

    } else {
        ((ImageView) findViewById(R.id.imageView)).setImageBitmap(
                BitmapFactory.decodeResource(getResources(), R.drawable.ic_action_folder_open_blue));

    }

    ((ImageView) findViewById(R.id.imageView)).addOnLayoutChangeListener(new View.OnLayoutChangeListener() {

        @Override
        public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop,
                int oldRight, int oldBottom) {
            // if layout is not complete we will get all zero values for the positions, so ignore the event
            if (left == 0 && top == 0 && right == 0 && bottom == 0) {
                return;
            } else {
                if (bitmapLoaded) {
                    try {
                        decodeImageUri(uriBitmapOriginal, (ImageView) findViewById(R.id.imageView));
                    } catch (FileNotFoundException e) {
                        Log.e(TAG, "Failed to grab Bitmap: " + e);
                    }
                    //if (iccProfileOut.isValidProfile() && iccProfileIn.isValidProfile())
                    transformImage();
                    updateImageViewer();

                }
            }

        }
    });

    ((SeekBar) findViewById(R.id.seekBarChromaPowerFactor))
            .setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
                @Override
                public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {

                }

                @Override
                public void onStartTrackingTouch(SeekBar seekBar) {

                }

                @Override
                public void onStopTrackingTouch(SeekBar seekBar) {
                    powerFactor = getPowerFactor(seekBar.getProgress());
                    //convertImage(seekBar);
                    //updateImageViewer();
                }
            });

    //when switching tabs, make sure:
    //a: update the image when switching to the imageview tab in case any settings changes were made
    //b: hide the color controls overlay if we are not on the imageview tab
    tabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() {
        @Override
        public void onTabChanged(String tabId) {
            if (tabId.equals(tabImageView.getTag())) {
                //Log.d(TAG,"Tab changed to image view");

                if (iccProfileIn.isValidProfile() && iccProfileOut.isValidProfile() && bitmapLoaded) {
                    recalculateTransform();
                    transformImage();
                    updateImageViewer();
                }
            } else if (tabId.equals(tabAbout.getTag())) {
                ((LinearLayout) findViewById(R.id.overlayColorControl)).setVisibility(View.INVISIBLE);
                InputStream inputStream = getResources().openRawResource(R.raw.about);
                ByteArrayOutputStream byteArrayStream = new ByteArrayOutputStream();
                try {
                    int bytesRead = inputStream.read();
                    while (bytesRead != -1) {
                        byteArrayStream.write(bytesRead);
                        bytesRead = inputStream.read();
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                }

                //TextView textViewAbout = (TextView) findViewById(R.id.textViewAbout);
                //textViewAbout.setText(Html.fromHtml(byteArrayStream.toString()));
                WebView webViewAbout = (WebView) findViewById(R.id.webViewAbout);
                webViewAbout.loadDataWithBaseURL(null, byteArrayStream.toString(), "text/html", "utf-8", null);
            } else {
                ((LinearLayout) findViewById(R.id.overlayColorControl)).setVisibility(View.INVISIBLE);
            }
        }
    });

}

From source file:com.mychild.view.Parent.CustomTabActivity.java

public void setUpTab() {
    final TabHost tabHost = (TabHost) findViewById(R.id.tabhost2);
    tabHost.setup();//from  w ww. j  ava 2 s .co m
    tabHost.getTabWidget().setDividerDrawable(R.drawable.tab_divider);
    class TabDef {
        public final String Indicator;//, Content;

        public TabDef(String Indicator, ListView lv) {
            this.Indicator = Indicator;
            //this.Content = Content;

        } /*TabDef*/
    }
    ; /*TabDef*/
    for (TabDef thisTab : new TabDef[] { new TabDef("Exams", examsListView),
            new TabDef("Results", examsListView) }) {

        //            final TextView contentview = new TextView(this);
        //            contentview.setText(thisTab.Content);

        View indicatorview = android.view.LayoutInflater.from(this).inflate(R.layout.tabs_bg_plain, null);
        TextView tabTitle = (TextView) indicatorview.findViewById(R.id.tabsText);
        tabTitle.setText(thisTab.Indicator);

        tabHost.addTab(tabHost.newTabSpec(thisTab.Indicator).setIndicator(indicatorview)
                .setContent(new TabHost.TabContentFactory() {
                    public View createTabContent(String tag) {
                        Log.i("Tagggggg:", tag);

                        if (tag == "Exams") {
                            return examsListView;
                        } else {
                            return examsListView;
                        }
                    } /*createTabContent*/
                }));/*TabContentFactory*/

    } /*for*/
}

From source file:com.example.mydemos.view.RingtonePickerActivity.java

/** Called when the activity is first created. */
@Override/*from   w  ww .ja  v  a 2 s  .c  om*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.ringtone_picker);
    CharSequence sysTitle = (CharSequence) getResources().getText(R.string.sys_tone);
    CharSequence MusicTitle = (CharSequence) getResources().getText(R.string.sd_music);
    CharSequence RecordTitle = (CharSequence) getResources().getText(R.string.record_tone);
    Intent intent = getIntent();
    toneType = intent.getIntExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, -1);

    Log.e("duwenhua", "ringPick get toneType:" + toneType);

    //! by duwenhua
    //if(toneType == RingtoneManager.TYPE_RINGTONE_SECOND)
    //    toneType = RINGTONE_TYPE;

    //! by duwenhua
    mHasDefaultItem = intent.getBooleanExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true);
    mUriForDefaultItem = intent.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI);
    //Log.i("lys", "mUriForDefaultItem == " + mUriForDefaultItem);
    if (savedInstanceState != null) {
        mSelectedId = savedInstanceState.getLong(SAVE_CLICKED_POS, -1);
    }
    //Log.i("lys", "mUriForDefaultItem 1== " + mUriForDefaultItem+", mSelectedId =="+mSelectedId);      
    mHasSilentItem = intent.getBooleanExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, true);
    mExistingUri = intent.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI);
    //if(mUriForDefaultItem != null)
    //{
    //    mSelectedId = ContentUris.parseId(mUriForDefaultItem);
    //}

    //Log.i("lys", "RingtonePickerActivity.java onCreate mExistingUri == " + mExistingUri);   
    //String action = getIntent().getAction();
    //Log.i("lys", "PT Intent action == " + action);

    if (toneType == NOTIFICATION_TYPE) {
        mUriForDefaultItem = Settings.System.DEFAULT_NOTIFICATION_URI;
    } else if (toneType == RINGTONE_TYPE) {
        mUriForDefaultItem = Settings.System.DEFAULT_RINGTONE_URI;
    } else if (toneType == ALARM_TYPE) {
        mUriForDefaultItem = Settings.System.DEFAULT_ALARM_ALERT_URI;
    }

    if (isAvailableToCheckRingtone() == true) {
        Ringtone ringtone_DefaultItem = checkRingtone_reflect(this, mUriForDefaultItem, toneType);
        if (ringtone_DefaultItem != null && ringtone_DefaultItem.getUri() != null) {
            mUriForDefaultItem = ringtone_DefaultItem.getUri();
            Log.i("lys", "RingtoneManager.getRingtone  mUriForDefaultItem== " + mUriForDefaultItem);
        } else {
            //mUriForDefaultItem = 'content/medial/';
            /*ZTE_AUDIO_LIYANG 2014/06/30 fix bug for ringtone when remove sdcard start */
            String originalRingtone = Settings.System.getString(getApplicationContext().getContentResolver(),
                    "ringtone_original");
            if (originalRingtone != null && !TextUtils.isEmpty(originalRingtone)) {
                mUriForDefaultItem = Uri.parse(originalRingtone);
                Log.e("liyang", "select riongtone error  ,change to originalRingtone == " + mExistingUri);
            }
            /*ZTE_AUDIO_LIYANG 2014/06/30 fix bug for ringtone when remove sdcard end */
            Log.i("lys", "mUriForDefaultItem set as default mUriForDefaultItem== 222");
        }

        if (mExistingUri != null) {
            Ringtone ringtone = checkRingtone_reflect(this, mExistingUri, toneType);
            if (ringtone != null && ringtone.getUri() != null) {
                //mUriForDefaultItem = ringtone.getUri(); 
                mExistingUri = ringtone.getUri();
                Log.i("lys", "RingtoneManager.getRingtone  mExistingUri== " + mExistingUri);
            } else {
                mExistingUri = mUriForDefaultItem;
                Log.i("lys", "mExistingUri set as default mExistingUri== " + mExistingUri);
            }
        }
    }

    boolean includeDrm = intent.getBooleanExtra(RingtoneManager.EXTRA_RINGTONE_INCLUDE_DRM, false);
    Log.e("lys", "includeDrm ==" + includeDrm);
    mRingtoneManager = new RingtoneManager(this);
    mRingtoneManager.setIncludeDrm(includeDrm);
    if (toneType != -1) {
        mRingtoneManager.setType(toneType);
    }

    setVolumeControlStream(mRingtoneManager.inferStreamType());
    //   toneActivityType = mRingtoneManager.getActivityType();
    if (toneType == ALARM_TYPE) {
        sysTitle = (CharSequence) getResources().getText(R.string.alarm_tone);
    } else if (toneType == NOTIFICATION_TYPE) {
        sysTitle = (CharSequence) getResources().getText(R.string.notification_tone);
    }

    listView = new ListView(this);
    listView.setOnItemClickListener(this);
    //listView.setBackgroundColor(#ff5a5a5a);
    listView.setFastScrollEnabled(true);
    //listView.setFastScrollAlwaysVisible(true);
    listView.setEmptyView(findViewById(android.R.id.empty));
    //mHasSilentItem = intent.getBooleanExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, true);

    //mHasDefaultItem = true; //temp
    if (mHasDefaultItem) {
        //chengcheng
        addDefaultStaticItem(listView, com.android.internal.R.string.ringtone_default);

    }

    setDefaultRingtone();

    if (mHasSilentItem) {
        // chengcheng
        addSilendStaticItem(listView, com.android.internal.R.string.ringtone_silent);
    }
    audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    mAudioFocusListener = new OnAudioFocusChangeListener() {
        public void onAudioFocusChange(int focusChange) {

        }
    };

    okBtn = (Button) findViewById(R.id.ok);
    okBtn.setOnClickListener(this);
    cancelBtn = (Button) findViewById(R.id.cancel);
    cancelBtn.setOnClickListener(this);

    TabHost mTabHost = (TabHost) findViewById(android.R.id.tabhost);
    mTabHost.setup();
    mTabHost.addTab(mTabHost.newTabSpec("tab_system").setIndicator(sysTitle, null).setContent(this));
    mTabHost.addTab(mTabHost.newTabSpec("tab_music").setIndicator(MusicTitle, null).setContent(this));
    mTabHost.addTab(mTabHost.newTabSpec("tab_record").setIndicator(RecordTitle, null).setContent(this));
    mTabHost.setCurrentTab(0);
    mTabHost.setOnTabChangedListener(new OnTabChangeListener() {
        @Override
        public void onTabChanged(String tabId) {
            // stopMediaPlayer();
            createTabContent(tabId);
        }
    });
}

From source file:eu.operando.operandoapp.OperandoProxyStatus.java

@Override
protected void onCreate(Bundle savedInstanceState) {

    MainUtil.initializeMainContext(getApplicationContext());
    Settings settings = mainContext.getSettings();
    settings.initializeDefaultValues();//from  ww  w .j av a2s. co  m
    setCurrentThemeStyle(settings.getThemeStyle());
    setTheme(getCurrentThemeStyle().themeAppCompatStyle());
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main_activity);
    settings.registerOnSharedPreferenceChangeListener(this);

    webView = (WebView) findViewById(R.id.webView);
    webView.getSettings().setJavaScriptEnabled(true);

    //region Floating Action Button

    fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (MainUtil.isServiceRunning(mainContext.getContext(), ProxyService.class)
                    && !MainUtil.isProxyPaused(mainContext)) {
                //Update Preferences to BypassProxy
                MainUtil.setProxyPaused(mainContext, true);
                fab.setImageResource(android.R.drawable.ic_media_play);
                //Toast.makeText(mainContext.getContext(), "-- bypass (disable) proxy --", Toast.LENGTH_SHORT).show();
            } else if (MainUtil.isServiceRunning(mainContext.getContext(), ProxyService.class)
                    && MainUtil.isProxyPaused(mainContext)) {

                MainUtil.setProxyPaused(mainContext, false);
                fab.setImageResource(android.R.drawable.ic_media_pause);
                //Toast.makeText(mainContext.getContext(), "-- re-enable proxy --", Toast.LENGTH_SHORT).show();
            } else if (!mainContext.getAuthority()
                    .aliasFile(BouncyCastleSslEngineSource.KEY_STORE_FILE_EXTENSION).exists()) {
                try {
                    installCert();
                } catch (RootCertificateException | GeneralSecurityException | OperatorCreationException
                        | IOException ex) {
                    Logger.error(this, ex.getMessage(), ex.getCause());
                }
            }
        }
    });

    //endregion

    //region TabHost

    final TabHost tabHost = (TabHost) findViewById(R.id.tabHost2);
    tabHost.setup();

    TabHost.TabSpec tabSpec = tabHost.newTabSpec("wifi_ap");
    tabSpec.setContent(R.id.WifiAndAccessPointsScrollView);
    tabSpec.setIndicator("", getResources().getDrawable(R.drawable.ic_home));
    tabHost.addTab(tabSpec);

    tabSpec = tabHost.newTabSpec("response_domain_filters");
    tabSpec.setContent(R.id.ResponseAndDomainFiltersScrollView);
    tabSpec.setIndicator("", getResources().getDrawable(R.drawable.ic_filter));
    tabHost.addTab(tabSpec);

    tabSpec = tabHost.newTabSpec("pending_notifications");
    tabSpec.setContent(R.id.PendingNotificationsScrollView);
    tabSpec.setIndicator("", getResources().getDrawable(R.drawable.ic_pending_notification));
    tabHost.addTab(tabSpec);

    tabSpec = tabHost.newTabSpec("logs");
    tabSpec.setContent(R.id.LogsScrollView);
    tabSpec.setIndicator("", getResources().getDrawable(R.drawable.ic_report));
    tabHost.addTab(tabSpec);

    tabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() {
        @Override
        public void onTabChanged(String tabId) {
            switch (tabId) {
            case "pending_notifications":
                //region Load Tab3
                ((TableLayout) ((LinearLayout) ((ScrollView) findViewById(R.id.PendingNotificationsScrollView))
                        .getChildAt(0)).getChildAt(1)).removeAllViews();
                LoadPendingNotificationsTab();
                //endregion
                break;
            case "logs":
                //region Load Tab 4
                //because it is a heavy task it is being loaded asynchronously
                ((TableLayout) ((LinearLayout) ((ScrollView) findViewById(R.id.LogsScrollView)).getChildAt(0))
                        .getChildAt(1)).removeAllViews();
                new AsyncTask() {
                    private ProgressDialog mProgress;
                    private List<String[]> apps;

                    @Override
                    protected void onPreExecute() {
                        super.onPreExecute();
                        mProgress = new ProgressDialog(MainActivity.this);
                        mProgress.setCancelable(false);
                        mProgress.setCanceledOnTouchOutside(false);
                        mProgress.setTitle("Fetching Application Data Logs");
                        mProgress.show();
                    }

                    @Override
                    protected Object doInBackground(Object[] params) {
                        apps = new ArrayList();
                        for (String[] app : getInstalledApps(false)) {
                            apps.add(new String[] { app[0], GetDataForApp(Integer.parseInt(app[1])) });
                        }
                        return null;
                    }

                    @Override
                    protected void onPostExecute(Object o) {
                        super.onPostExecute(o);
                        mProgress.dismiss();
                        for (String[] app : apps) {
                            if (app[0].contains(".")) {
                                continue;
                            }
                            TextView tv = new TextView(MainActivity.this);
                            tv.setTextSize(18);
                            tv.setText(app[0] + " || " + app[1]);
                            ((TableLayout) ((LinearLayout) ((ScrollView) findViewById(R.id.LogsScrollView))
                                    .getChildAt(0)).getChildAt(1)).addView(tv);

                            View separator = new View(MainActivity.this);
                            separator.setBackgroundColor(Color.BLACK);
                            separator.setLayoutParams(
                                    new TableRow.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 5));
                            ((TableLayout) ((LinearLayout) ((ScrollView) findViewById(R.id.LogsScrollView))
                                    .getChildAt(0)).getChildAt(1)).addView(separator);
                        }
                    }
                }.execute();
                //endregion
                break;
            }
        }
    });

    //endregion

    //region Buttons

    WiFiAPButton = (Button) findViewById(R.id.WiFiAPButton);
    WiFiAPButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Intent i = new Intent(mainContext.getContext(), AccessPointsActivity.class);
            startActivity(i);
        }
    });

    responseFiltersButton = (Button) findViewById(R.id.responseFiltersButton);
    responseFiltersButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent i = new Intent(mainContext.getContext(), ResponseFiltersActivity.class);
            startActivity(i);
        }
    });

    domainFiltersButton = (Button) findViewById(R.id.domainFiltersButton);
    domainFiltersButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent i = new Intent(mainContext.getContext(), DomainFiltersActivity.class);
            startActivity(i);
        }
    });

    domainManagerButton = (Button) findViewById(R.id.domainManagerButton);
    domainManagerButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent i = new Intent(mainContext.getContext(), DomainManagerActivity.class);
            startActivity(i);
        }
    });

    permissionsPerDomainButton = (Button) findViewById(R.id.permissionsPerDomainButton);
    permissionsPerDomainButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent i = new Intent(mainContext.getContext(), PermissionsPerDomainActivity.class);
            startActivity(i);
        }
    });

    trustedAccessPointsButton = (Button) findViewById(R.id.trustedAccessPointsButton);
    trustedAccessPointsButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent i = new Intent(mainContext.getContext(), TrustedAccessPointsActivity.class);
            startActivity(i);
        }
    });

    updateButton = (Button) findViewById(R.id.updateButton);
    updateButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // mark first time has not runned and update like it's initial .
            final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(MainActivity.this);
            SharedPreferences.Editor editor = prefs.edit();
            editor.putBoolean("firstTime", true);
            editor.commit();
            DownloadInitialSettings();
        }
    });

    statisticsButton = (Button) findViewById(R.id.statisticsButton);
    statisticsButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent i = new Intent(mainContext.getContext(), StatisticsActivity.class);
            startActivity(i);
        }
    });

    //endregion

    //region Action Bar
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        setTitle(R.string.app_name);
    }

    //endregion

    //region Send Cached Settings
    //send cached settings if exist...
    BufferedReader br = null;
    try {
        File file = new File(MainContext.INSTANCE.getContext().getFilesDir(), "resend.inf");
        StringBuilder content = new StringBuilder();
        br = new BufferedReader(new FileReader(file));
        String line;
        while ((line = br.readLine()) != null) {
            content.append(line);
        }
        if (content.toString().equals("1")) {
            File f = new File(file.getCanonicalPath());
            f.delete();
            new DatabaseHelper(MainActivity.this)
                    .sendSettingsToServer(new RequestFilterUtil(MainActivity.this).getIMEI());
        }
    } catch (Exception ex) {
        ex.getMessage();
    } finally {
        try {
            br.close();
        } catch (Exception ex) {
            ex.getMessage();
        }
    }
    //endregion

    initializeProxyService();
}

From source file:org.runnerup.view.DetailActivity.java

/** Called when the activity is first created. */
@Override/*  w ww  .  jav a  2  s .c  o  m*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.detail);
    WidgetUtil.addLegacyOverflowButton(getWindow());

    Intent intent = getIntent();
    mID = intent.getLongExtra("ID", -1);
    String mode = intent.getStringExtra("mode");

    mDBHelper = new DBHelper(this);
    mDB = mDBHelper.getReadableDatabase();
    uploadManager = new UploadManager(this);
    formatter = new Formatter(this);

    if (mode.contentEquals("save")) {
        this.mode = MODE_SAVE;
    } else if (mode.contentEquals("details")) {
        this.mode = MODE_DETAILS;
    } else {
        assert (false);
    }

    saveButton = (Button) findViewById(R.id.save_button);
    discardButton = (Button) findViewById(R.id.discard_button);
    resumeButton = (Button) findViewById(R.id.resume_button);
    uploadButton = (Button) findViewById(R.id.upload_button);
    activityTime = (TextView) findViewById(R.id.activity_time);
    activityDistance = (TextView) findViewById(R.id.activity_distance);
    activityPace = (TextView) findViewById(R.id.activity_pace);
    sport = (TitleSpinner) findViewById(R.id.summary_sport);
    notes = (EditText) findViewById(R.id.notes_text);
    notes.setHint("Notes about your workout");
    map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();

    if (map != null) {
        map.setOnCameraChangeListener(new OnCameraChangeListener() {

            @Override
            public void onCameraChange(CameraPosition arg0) {
                if (mapBounds != null) {
                    // Move camera.
                    map.moveCamera(CameraUpdateFactory.newLatLngBounds(mapBounds, 5));
                    // Remove listener to prevent position reset on camera
                    // move.
                    map.setOnCameraChangeListener(null);
                }
            }
        });
    }
    saveButton.setOnClickListener(saveButtonClick);
    uploadButton.setOnClickListener(uploadButtonClick);
    if (this.mode == MODE_SAVE) {
        resumeButton.setOnClickListener(resumeButtonClick);
        discardButton.setOnClickListener(discardButtonClick);
        setEdit(true);
    } else if (this.mode == MODE_DETAILS) {
        resumeButton.setVisibility(View.GONE);
        discardButton.setVisibility(View.GONE);
        setEdit(false);
    }
    uploadButton.setVisibility(View.GONE);

    fillHeaderData();
    requery();

    loadRoute();

    TabHost th = (TabHost) findViewById(R.id.tabhost);
    th.setup();
    TabSpec tabSpec = th.newTabSpec("notes");
    tabSpec.setIndicator(WidgetUtil.createHoloTabIndicator(this, "Notes"));
    tabSpec.setContent(R.id.tab_main);
    th.addTab(tabSpec);

    tabSpec = th.newTabSpec("laps");
    tabSpec.setIndicator(WidgetUtil.createHoloTabIndicator(this, "Laps"));
    tabSpec.setContent(R.id.tab_lap);
    th.addTab(tabSpec);

    tabSpec = th.newTabSpec("map");
    tabSpec.setIndicator(WidgetUtil.createHoloTabIndicator(this, "Map"));
    tabSpec.setContent(R.id.tab_map);
    th.addTab(tabSpec);

    tabSpec = th.newTabSpec("graph");
    tabSpec.setIndicator(WidgetUtil.createHoloTabIndicator(this, "Graph"));
    tabSpec.setContent(R.id.tab_graph);
    th.addTab(tabSpec);

    tabSpec = th.newTabSpec("share");
    tabSpec.setIndicator(WidgetUtil.createHoloTabIndicator(this, "Upload"));
    tabSpec.setContent(R.id.tab_upload);
    th.addTab(tabSpec);

    th.getTabWidget().setBackgroundColor(Color.DKGRAY);

    {
        ListView lv = (ListView) findViewById(R.id.laplist);
        LapListAdapter adapter = new LapListAdapter();
        adapters.add(adapter);
        lv.setAdapter(adapter);
    }
    {
        ListView lv = (ListView) findViewById(R.id.report_list);
        ReportListAdapter adapter = new ReportListAdapter();
        adapters.add(adapter);
        lv.setAdapter(adapter);
    }
    graphTab = (LinearLayout) findViewById(R.id.tab_graph);
    {
        graphView = new LineGraphView(this, "Pace") {
            @Override
            protected String formatLabel(double value, boolean isValueX) {
                if (!isValueX) {
                    return formatter.formatPace(Formatter.TXT_SHORT, value);
                } else
                    return formatter.formatDistance(Formatter.TXT_SHORT, (long) value);
            }
        };

        graphView2 = new LineGraphView(this, "HRM") {
            @Override
            protected String formatLabel(double value, boolean isValueX) {
                if (!isValueX) {
                    return Integer.toString((int) Math.round(value));
                } else {
                    return formatter.formatDistance(Formatter.TXT_SHORT, (long) value);
                }
            }
        };
    }
    hrzonesBarLayout = (LinearLayout) findViewById(R.id.hrzonesBarLayout);
    hrzonesBar = new HRZonesBar(this);
}

From source file:com.momock.outlet.tab.FragmentTabOutlet.java

public void attach(FragmentTabHolder tabHolder) {
    Logger.check(tabHolder != null, "Parameter tabHolder cannot be null!");
    this.target = tabHolder;
    TabHost tabHost = target.getTabHost();
    final IDataList<IPlug> plugs = getPlugs();
    tabHost.setup();//from w  w  w  .j a v  a 2 s. c  om
    tabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() {

        @Override
        public void onTabChanged(String tabId) {
            new Handler().post(new Runnable() {

                @Override
                public void run() {
                    int index = target.getTabHost().getCurrentTab();
                    int id = target.getTabContentId();
                    ITabPlug plug = (ITabPlug) plugs.getItem(index);
                    setActivePlug(plug);

                    FragmentManager fm = target.getFragmentManager();
                    if (fm != null && plug.getContent() instanceof FragmentHolder) {
                        try {
                            FragmentTransaction ft = fm.beginTransaction();
                            FragmentHolder fh = (FragmentHolder) plug.getContent();
                            ft.replace(id, fh.getFragment());
                            ft.commit();
                            fm.executePendingTransactions();
                        } catch (Exception e) {
                            Logger.error(e);
                        }
                    }
                }

            });
        }
    });
    for (int i = 0; i < plugs.getItemCount(); i++) {
        final ITabPlug plug = (ITabPlug) plugs.getItem(i);
        if (plug.getContent() instanceof FragmentHolder) {
            TabHost.TabSpec spec = tabHost.newTabSpec("" + i);
            target.setTabIndicator(spec, plug);
            spec.setContent(new TabContentFactory() {

                @Override
                public View createTabContent(String tag) {
                    View v = new View(target.getTabHost().getContext());
                    v.setMinimumWidth(0);
                    v.setMinimumHeight(0);
                    return v;
                }

            });
            tabHost.addTab(spec);
            if (getActivePlug() == plug)
                tabHost.setCurrentTab(i);
        }
    }
}

From source file:com.jtechme.apphub.privileged.views.InstallConfirmActivity.java

private void startInstallConfirm() {

    final Drawable appIcon = mAppDiff.mPkgInfo.applicationInfo.loadIcon(mPm);
    final String appLabel = (String) mAppDiff.mPkgInfo.applicationInfo.loadLabel(mPm);

    View appSnippet = findViewById(R.id.app_snippet);
    ((ImageView) appSnippet.findViewById(R.id.app_icon)).setImageDrawable(appIcon);
    ((TextView) appSnippet.findViewById(R.id.app_name)).setText(appLabel);

    TabHost tabHost = (TabHost) findViewById(android.R.id.tabhost);
    tabHost.setup();/* ww  w. ja  v  a2 s. c  o m*/
    ViewPager viewPager = (ViewPager) findViewById(R.id.pager);
    TabsAdapter adapter = new TabsAdapter(this, tabHost, viewPager);
    adapter.setOnTabChangedListener(new TabHost.OnTabChangeListener() {
        @Override
        public void onTabChanged(String tabId) {
        }
    });

    boolean permVisible = false;
    mScrollView = null;
    mOkCanInstall = false;
    int msg = 0;
    AppSecurityPermissions perms = new AppSecurityPermissions(this, mAppDiff.mPkgInfo);
    if (mAppDiff.mInstalledAppInfo != null) {
        msg = (mAppDiff.mInstalledAppInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0
                ? R.string.install_confirm_update_system
                : R.string.install_confirm_update;
        mScrollView = new CaffeinatedScrollView(this);
        mScrollView.setFillViewport(true);
        final boolean newPermissionsFound = perms.getPermissionCount(AppSecurityPermissions.WHICH_NEW) > 0;
        if (newPermissionsFound) {
            permVisible = true;
            mScrollView.addView(perms.getPermissionsView(AppSecurityPermissions.WHICH_NEW));
        } else {
            throw new RuntimeException(
                    "This should not happen. No new permissions were found but InstallConfirmActivity has been started!");
        }
        adapter.addTab(tabHost.newTabSpec(TAB_ID_NEW).setIndicator(getText(R.string.newPerms)), mScrollView);
    } else {
        findViewById(R.id.tabscontainer).setVisibility(View.GONE);
        findViewById(R.id.divider).setVisibility(View.VISIBLE);
    }
    final int np = perms.getPermissionCount(AppSecurityPermissions.WHICH_PERSONAL);
    final int nd = perms.getPermissionCount(AppSecurityPermissions.WHICH_DEVICE);
    if (np > 0 || nd > 0) {
        permVisible = true;
        LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View root = inflater.inflate(R.layout.permissions_list, null);
        if (mScrollView == null) {
            mScrollView = (CaffeinatedScrollView) root.findViewById(R.id.scrollview);
        }
        final ViewGroup privacyList = (ViewGroup) root.findViewById(R.id.privacylist);
        if (np > 0) {
            privacyList.addView(perms.getPermissionsView(AppSecurityPermissions.WHICH_PERSONAL));
        } else {
            privacyList.setVisibility(View.GONE);
        }
        final ViewGroup deviceList = (ViewGroup) root.findViewById(R.id.devicelist);
        if (nd > 0) {
            deviceList.addView(perms.getPermissionsView(AppSecurityPermissions.WHICH_DEVICE));
        } else {
            root.findViewById(R.id.devicelist).setVisibility(View.GONE);
        }
        adapter.addTab(tabHost.newTabSpec(TAB_ID_ALL).setIndicator(getText(R.string.allPerms)), root);
    }

    if (!permVisible) {
        if (mAppDiff.mInstalledAppInfo != null) {
            // This is an update to an application, but there are no
            // permissions at all.
            msg = (mAppDiff.mInstalledAppInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0
                    ? R.string.install_confirm_update_system_no_perms
                    : R.string.install_confirm_update_no_perms;
        } else {
            // This is a new application with no permissions.
            msg = R.string.install_confirm_no_perms;
        }
        tabHost.setVisibility(View.GONE);
        findViewById(R.id.filler).setVisibility(View.VISIBLE);
        findViewById(R.id.divider).setVisibility(View.GONE);
        mScrollView = null;
    }
    if (msg != 0) {
        ((TextView) findViewById(R.id.install_confirm)).setText(msg);
    }
    mInstallConfirm.setVisibility(View.VISIBLE);
    mOk = (Button) findViewById(R.id.ok_button);
    mCancel = (Button) findViewById(R.id.cancel_button);
    mOk.setOnClickListener(this);
    mCancel.setOnClickListener(this);
    if (mScrollView == null) {
        // There is nothing to scroll view, so the ok button is immediately
        // set to install.
        mOk.setText(R.string.menu_install);
        mOkCanInstall = true;
    } else {
        mScrollView.setFullScrollAction(new Runnable() {
            @Override
            public void run() {
                mOk.setText(R.string.menu_install);
                mOkCanInstall = true;
            }
        });
    }
}