Example usage for android.widget TabHost setup

List of usage examples for android.widget TabHost setup

Introduction

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

Prototype

public void setup() 

Source Link

Document

Call setup() before adding tabs if loading TabHost using findViewById().

Usage

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;
    }//www.  j a va2s  . com
    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:com.android.packageinstaller.PackageInstallerActivity.java

private void startInstallConfirm() {
    TabHost tabHost = (TabHost) findViewById(android.R.id.tabhost);
    tabHost.setup();
    tabHost.setVisibility(View.VISIBLE);
    ViewPager viewPager = (ViewPager) findViewById(R.id.pager);
    TabsAdapter adapter = new TabsAdapter(this, tabHost, viewPager);
    // If the app supports runtime permissions the new permissions will
    // be requested at runtime, hence we do not show them at install.
    boolean supportsRuntimePermissions = mPkgInfo.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.M;
    boolean permVisible = false;
    mScrollView = null;/*  w w w .ja v a2s  .  com*/
    mOkCanInstall = false;
    int msg = 0;

    AppSecurityPermissions perms = new AppSecurityPermissions(this, mPkgInfo);
    final int N = perms.getPermissionCount(AppSecurityPermissions.WHICH_ALL);
    if (mAppInfo != null) {
        msg = (mAppInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0
                ? R.string.install_confirm_question_update_system
                : R.string.install_confirm_question_update;
        mScrollView = new CaffeinatedScrollView(this);
        mScrollView.setFillViewport(true);
        boolean newPermissionsFound = false;
        if (!supportsRuntimePermissions) {
            newPermissionsFound = (perms.getPermissionCount(AppSecurityPermissions.WHICH_NEW) > 0);
            if (newPermissionsFound) {
                permVisible = true;
                mScrollView.addView(perms.getPermissionsView(AppSecurityPermissions.WHICH_NEW));
            }
        }
        if (!supportsRuntimePermissions && !newPermissionsFound) {
            LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            TextView label = (TextView) inflater.inflate(R.layout.label, null);
            label.setText(R.string.no_new_perms);
            mScrollView.addView(label);
        }
        adapter.addTab(tabHost.newTabSpec(TAB_ID_NEW).setIndicator(getText(R.string.newPerms)), mScrollView);
    } else {
        findViewById(R.id.tabscontainer).setVisibility(View.GONE);
        findViewById(R.id.spacer).setVisibility(View.VISIBLE);
    }
    if (!supportsRuntimePermissions && N > 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);
        }
        ((ViewGroup) root.findViewById(R.id.permission_list))
                .addView(perms.getPermissionsView(AppSecurityPermissions.WHICH_ALL));
        adapter.addTab(tabHost.newTabSpec(TAB_ID_ALL).setIndicator(getText(R.string.allPerms)), root);
    }
    if (!permVisible) {
        if (mAppInfo != null) {
            // This is an update to an application, but there are no
            // permissions at all.
            msg = (mAppInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0
                    ? R.string.install_confirm_question_update_system_no_perms
                    : R.string.install_confirm_question_update_no_perms;

            findViewById(R.id.spacer).setVisibility(View.VISIBLE);
        } else {
            // This is a new application with no permissions.
            msg = R.string.install_confirm_question_no_perms;
        }
        tabHost.setVisibility(View.INVISIBLE);
        mScrollView = null;
    }
    if (msg != 0) {
        ((TextView) findViewById(R.id.install_confirm_question)).setText(msg);
    }
    mInstallConfirm.setVisibility(View.VISIBLE);
    mOk.setEnabled(true);
    if (mScrollView == null) {
        // There is nothing to scroll view, so the ok button is immediately
        // set to install.
        mOk.setText(R.string.install);
        mOkCanInstall = true;
    } else {
        mScrollView.setFullScrollAction(new Runnable() {
            @Override
            public void run() {
                mOk.setText(R.string.install);
                mOkCanInstall = true;
            }
        });
    }
}

From source file:com.example.android.mediarouter.player.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    // Be sure to call the super class.
    super.onCreate(savedInstanceState);
    if (savedInstanceState != null) {
        mPlayer = (Player) savedInstanceState.getSerializable("mPlayer");
    }/*w  w w.ja va  2  s  . com*/

    // Get the media router service.
    mMediaRouter = MediaRouter.getInstance(this);

    // Create a route selector for the type of routes that we care about.
    mSelector = new MediaRouteSelector.Builder().addControlCategory(MediaControlIntent.CATEGORY_LIVE_AUDIO)
            .addControlCategory(MediaControlIntent.CATEGORY_LIVE_VIDEO)
            .addControlCategory(MediaControlIntent.CATEGORY_REMOTE_PLAYBACK)
            .addControlCategory(SampleMediaRouteProvider.CATEGORY_SAMPLE_ROUTE).build();

    // Add a fragment to take care of media route discovery.
    // This fragment automatically adds or removes a callback whenever the activity
    // is started or stopped.
    FragmentManager fm = getSupportFragmentManager();
    DiscoveryFragment fragment = (DiscoveryFragment) fm.findFragmentByTag(DISCOVERY_FRAGMENT_TAG);
    if (fragment == null) {
        fragment = new DiscoveryFragment(mMediaRouterCB);
        fragment.setRouteSelector(mSelector);
        fm.beginTransaction().add(fragment, DISCOVERY_FRAGMENT_TAG).commit();
    } else {
        fragment.setCallback(mMediaRouterCB);
        fragment.setRouteSelector(mSelector);
    }

    // Populate an array adapter with streaming media items.
    String[] mediaNames = getResources().getStringArray(R.array.media_names);
    String[] mediaUris = getResources().getStringArray(R.array.media_uris);
    mLibraryItems = new LibraryAdapter();
    for (int i = 0; i < mediaNames.length; i++) {
        mLibraryItems.add(new MediaItem("[streaming] " + mediaNames[i], Uri.parse(mediaUris[i]), "video/mp4"));
    }

    // Scan local external storage directory for media files.
    File externalDir = Environment.getExternalStorageDirectory();
    if (externalDir != null) {
        File list[] = externalDir.listFiles();
        if (list != null) {
            for (int i = 0; i < list.length; i++) {
                String filename = list[i].getName();
                if (filename.matches(".*\\.(m4v|mp4)")) {
                    mLibraryItems.add(new MediaItem("[local] " + filename, Uri.fromFile(list[i]), "video/mp4"));
                }
            }
        }
    }

    mPlayListItems = new PlaylistAdapter();

    // Initialize the layout.
    setContentView(R.layout.sample_media_router);

    TabHost tabHost = (TabHost) findViewById(R.id.tabHost);
    tabHost.setup();
    String tabName = getResources().getString(R.string.library_tab_text);
    TabSpec spec1 = tabHost.newTabSpec(tabName);
    spec1.setContent(R.id.tab1);
    spec1.setIndicator(tabName);

    tabName = getResources().getString(R.string.playlist_tab_text);
    TabSpec spec2 = tabHost.newTabSpec(tabName);
    spec2.setIndicator(tabName);
    spec2.setContent(R.id.tab2);

    tabName = getResources().getString(R.string.statistics_tab_text);
    TabSpec spec3 = tabHost.newTabSpec(tabName);
    spec3.setIndicator(tabName);
    spec3.setContent(R.id.tab3);

    tabHost.addTab(spec1);
    tabHost.addTab(spec2);
    tabHost.addTab(spec3);
    tabHost.setOnTabChangedListener(new OnTabChangeListener() {
        @Override
        public void onTabChanged(String arg0) {
            updateUi();
        }
    });

    mLibraryView = (ListView) findViewById(R.id.media);
    mLibraryView.setAdapter(mLibraryItems);
    mLibraryView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
    mLibraryView.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            updateButtons();
        }
    });

    mPlayListView = (ListView) findViewById(R.id.playlist);
    mPlayListView.setAdapter(mPlayListItems);
    mPlayListView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
    mPlayListView.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            updateButtons();
        }
    });

    mInfoTextView = (TextView) findViewById(R.id.info);

    mPauseResumeButton = (ImageButton) findViewById(R.id.pause_resume_button);
    mPauseResumeButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            mPaused = !mPaused;
            if (mPaused) {
                mSessionManager.pause();
            } else {
                mSessionManager.resume();
            }
        }
    });

    mStopButton = (ImageButton) findViewById(R.id.stop_button);
    mStopButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            mPaused = false;
            mSessionManager.stop();
        }
    });

    mSeekBar = (SeekBar) findViewById(R.id.seekbar);
    mSeekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            PlaylistItem item = getCheckedPlaylistItem();
            if (fromUser && item != null && item.getDuration() > 0) {
                long pos = progress * item.getDuration() / 100;
                mSessionManager.seek(item.getItemId(), pos);
                item.setPosition(pos);
                item.setTimestamp(SystemClock.elapsedRealtime());
            }
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
            mSeeking = true;
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
            mSeeking = false;
            updateUi();
        }
    });

    // Schedule Ui update
    mHandler.postDelayed(mUpdateSeekRunnable, 1000);

    // Build the PendingIntent for the remote control client
    mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    mEventReceiver = new ComponentName(getPackageName(), SampleMediaButtonReceiver.class.getName());
    Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON);
    mediaButtonIntent.setComponent(mEventReceiver);
    mMediaPendingIntent = PendingIntent.getBroadcast(this, 0, mediaButtonIntent, 0);

    // Create and register the remote control client
    registerRemoteControlClient();

    // Set up playback manager and player
    mPlayer = Player.create(MainActivity.this, mMediaRouter.getSelectedRoute());
    mSessionManager.setPlayer(mPlayer);
    mSessionManager.setCallback(new SessionManager.Callback() {
        @Override
        public void onStatusChanged() {
            updateUi();
        }

        @Override
        public void onItemChanged(PlaylistItem item) {
        }
    });

    updateUi();
}

From source file:com.example.android.mediarouter.player.RadioActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    // Be sure to call the super class.
    super.onCreate(savedInstanceState);
    if (savedInstanceState != null) {
        mPlayer = (RadioPlayer) savedInstanceState.getSerializable("mPlayer");
    }/*  w  w w.jav a  2s  .  com*/

    // Get the media router service.
    mMediaRouter = MediaRouter.getInstance(this);

    // Create a route selector for the type of routes that we care about.
    mSelector = new MediaRouteSelector.Builder().addControlCategory(MediaControlIntent.CATEGORY_LIVE_AUDIO)
            .addControlCategory(MediaControlIntent.CATEGORY_LIVE_VIDEO)
            .addControlCategory(MediaControlIntent.CATEGORY_REMOTE_PLAYBACK)
            .addControlCategory(SampleMediaRouteProvider.CATEGORY_SAMPLE_ROUTE).build();

    // Add a fragment to take care of media route discovery.
    // This fragment automatically adds or removes a callback whenever the activity
    // is started or stopped.
    FragmentManager fm = getSupportFragmentManager();
    DiscoveryFragment fragment = (DiscoveryFragment) fm.findFragmentByTag(DISCOVERY_FRAGMENT_TAG);
    if (fragment == null) {
        fragment = new DiscoveryFragment(mMediaRouterCB);
        fragment.setRouteSelector(mSelector);
        fm.beginTransaction().add(fragment, DISCOVERY_FRAGMENT_TAG).commit();
    } else {
        fragment.setCallback(mMediaRouterCB);
        fragment.setRouteSelector(mSelector);
    }

    // Populate an array adapter with streaming media items.
    String[] mediaNames = getResources().getStringArray(R.array.media_names);
    String[] mediaUris = getResources().getStringArray(R.array.media_uris);
    mLibraryItems = new LibraryAdapter();
    for (int i = 0; i < mediaNames.length; i++) {
        mLibraryItems.add(new MediaItem("[streaming] " + mediaNames[i], Uri.parse(mediaUris[i]), "video/mp4"));
    }

    // Scan local external storage directory for media files.
    File externalDir = Environment.getExternalStorageDirectory();
    if (externalDir != null) {
        File list[] = externalDir.listFiles();
        if (list != null) {
            for (int i = 0; i < list.length; i++) {
                String filename = list[i].getName();
                if (filename.matches(".*\\.(m4v|mp4)")) {
                    mLibraryItems.add(new MediaItem("[local] " + filename, Uri.fromFile(list[i]), "video/mp4"));
                }
            }
        }
    }

    mPlayListItems = new PlaylistAdapter();

    // Initialize the layout.
    setContentView(R.layout.sample_radio_router);

    TabHost tabHost = (TabHost) findViewById(R.id.tabHost);
    tabHost.setup();
    String tabName = getResources().getString(R.string.library_tab_text);
    TabSpec spec1 = tabHost.newTabSpec(tabName);
    spec1.setContent(R.id.tab1);
    spec1.setIndicator(tabName);

    tabName = getResources().getString(R.string.playlist_tab_text);
    TabSpec spec2 = tabHost.newTabSpec(tabName);
    spec2.setIndicator(tabName);
    spec2.setContent(R.id.tab2);

    tabName = getResources().getString(R.string.statistics_tab_text);
    TabSpec spec3 = tabHost.newTabSpec(tabName);
    spec3.setIndicator(tabName);
    spec3.setContent(R.id.tab3);

    tabHost.addTab(spec1);
    tabHost.addTab(spec2);
    tabHost.addTab(spec3);
    tabHost.setOnTabChangedListener(new OnTabChangeListener() {
        @Override
        public void onTabChanged(String arg0) {
            updateUi();
        }
    });

    mLibraryView = (ListView) findViewById(R.id.media);
    mLibraryView.setAdapter(mLibraryItems);
    mLibraryView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
    mLibraryView.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            updateButtons();
        }
    });

    mPlayListView = (ListView) findViewById(R.id.playlist);
    mPlayListView.setAdapter(mPlayListItems);
    mPlayListView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
    mPlayListView.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            updateButtons();
        }
    });

    mInfoTextView = (TextView) findViewById(R.id.info);

    mPauseResumeButton = (ImageButton) findViewById(R.id.pause_resume_button);
    mPauseResumeButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            mPaused = !mPaused;
            if (mPaused) {
                mSessionManager.pause();
            } else {
                mSessionManager.resume();
            }
        }
    });

    mStopButton = (ImageButton) findViewById(R.id.stop_button);
    mStopButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            mPaused = false;
            mSessionManager.stop();
        }
    });

    mSeekBar = (SeekBar) findViewById(R.id.seekbar);
    mSeekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            PlaylistItem item = getCheckedPlaylistItem();
            if (fromUser && item != null && item.getDuration() > 0) {
                long pos = progress * item.getDuration() / 100;
                mSessionManager.seek(item.getItemId(), pos);
                item.setPosition(pos);
                item.setTimestamp(SystemClock.elapsedRealtime());
            }
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
            mSeeking = true;
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
            mSeeking = false;
            updateUi();
        }
    });

    // Schedule Ui update
    mHandler.postDelayed(mUpdateSeekRunnable, 1000);

    // Build the PendingIntent for the remote control client
    mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    mEventReceiver = new ComponentName(getPackageName(), SampleMediaButtonReceiver.class.getName());
    Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON);
    mediaButtonIntent.setComponent(mEventReceiver);
    mMediaPendingIntent = PendingIntent.getBroadcast(this, 0, mediaButtonIntent, 0);

    // Create and register the remote control client
    registerRemoteControlClient();

    // Set up playback manager and player
    mPlayer = RadioPlayer.create(RadioActivity.this, mMediaRouter.getSelectedRoute());
    mSessionManager.setPlayer(mPlayer);
    mSessionManager.setCallback(new RadioSessionManager.Callback() {
        @Override
        public void onStatusChanged() {
            updateUi();
        }

        @Override
        public void onItemChanged(PlaylistItem item) {
        }
    });

    updateUi();
}

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();

    // Adding Ride tab
    TabHost.TabSpec specRide = tabs.newTabSpec("tag1");
    specRide.setContent(R.id.ride_tab);/*from   w  w  w .j a v  a  2s .c o  m*/
    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();

    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);/* w  w w  .  ja  v a2  s. c  o m*/

    /** 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:eu.operando.operandoapp.OperandoProxyStatus.java

@Override
protected void onCreate(Bundle savedInstanceState) {

    MainUtil.initializeMainContext(getApplicationContext());
    Settings settings = mainContext.getSettings();
    settings.initializeDefaultValues();//from   w  w w  .  ja va2 s.c o  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:com.example.mydemos.view.RingtonePickerActivity.java

/** Called when the activity is first created. */
@Override/*from ww w.ja va 2  s  .c  o m*/
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:org.runnerup.view.DetailActivity.java

/** Called when the activity is first created. */
@Override/*from   w  w  w  . j  a v  a 2 s  .co  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.PagerTabOutlet.java

public void attach(TabHolder target) {
    Logger.check(target != null, "Parameter target cannot be null!");
    Logger.check(target.getTabContent() instanceof ViewPager,
            "The PagerTabOutlet must contains a ViewPager content!");
    this.target = target;
    final TabHost tabHost = target.getTabHost();
    final ViewPager tabContent = (ViewPager) target.getTabContent();
    plugs = getPlugs();//w ww.j  a  v  a2s .  c om

    ViewPager pager = (ViewPager) target.getTabContent();
    for (int i = 0; i < plugs.getItemCount(); i++) {
        ITabPlug plug = (ITabPlug) plugs.getItem(i);
        Logger.check(plug.getContent() instanceof ViewHolder,
                "The plug of PagerTabOutlet must include a ViewHolder!");
        ((ViewHolder) plug.getContent()).reset();
    }
    pager.setAdapter(new PagerAdapter() {

        @Override
        public int getCount() {
            return plugs.getItemCount();
        }

        @Override
        public boolean isViewFromObject(View view, Object object) {
            return view == object;
        }

        @Override
        public Object instantiateItem(ViewGroup container, int position) {
            ITabPlug plug = (ITabPlug) plugs.getItem(position);
            View view = ((ViewHolder) plug.getContent()).getView();
            container.addView(view);
            return view;
        }

        @Override
        public void destroyItem(ViewGroup container, int position, Object object) {
            container.removeView((View) object);
        }
    });

    tabContent.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {

        @Override
        public void onPageSelected(int position) {
            TabWidget widget = tabHost.getTabWidget();
            int oldFocusability = widget.getDescendantFocusability();
            widget.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);
            tabHost.setCurrentTab(position);
            widget.setDescendantFocusability(oldFocusability);
        }

        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

        }

        @Override
        public void onPageScrollStateChanged(int state) {

        }
    });
    tabHost.setup();
    tabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() {

        @Override
        public void onTabChanged(String tabId) {
            int index = tabHost.getCurrentTab();
            ITabPlug plug = (ITabPlug) plugs.getItem(index);
            setActivePlug(plug);
            tabContent.setCurrentItem(index, true);
        }
    });
    for (int i = 0; i < plugs.getItemCount(); i++) {
        final ITabPlug plug = (ITabPlug) plugs.getItem(i);
        Logger.check(plug.getContent() instanceof ViewHolder,
                "Plug in PagerTabOutlet must contains a ViewHolder content!");

        TabHost.TabSpec spec = tabHost.newTabSpec("" + i);
        target.setTabIndicator(spec, plug);
        spec.setContent(new TabContentFactory() {

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

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