Android Open Source - androidui Main Activity






From Project

Back to project page androidui.

License

The source code is released under:

MIT License

If you think the Android project androidui listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package course.examples.modernartui;
//  w w w  .j  a  v a 2s  .c  o m
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.net.Uri;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class MainActivity extends Activity {

  private ImageView mLeftOne, mLeftTwo, mRightOne, mRightThree;

    private static final int MAX_TINT = 150;
    private static final int MAX_COLOR_COMP = 255;
    private static final String VISIT_MOMA_URL = "http://www.moma.org";

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    setupTintControl();
    initViews();

  }

  // Set up the SeekBar the manages the tint level
  private void setupTintControl() {

        SeekBar tintControl = (SeekBar) findViewById(R.id.slider);
        tintControl.setMax(MAX_TINT);
        tintControl.setProgress(0);

    // Set an OnSeekBarChangeListener on the
        tintControl.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

            static final int MAX_THREADS = 4;

            // Use a ThreadPoolExecutor to handle the work of responding to tint
            // control. Using the DiscardOldestPolicy to throw away oldest work
            // requests if too many jobs are scheduled.

            final ThreadPoolExecutor executor = new ThreadPoolExecutor(MAX_THREADS,
                    MAX_THREADS, Long.MAX_VALUE, TimeUnit.SECONDS,
                    new ArrayBlockingQueue<Runnable>(MAX_THREADS),
                    new ThreadPoolExecutor.DiscardOldestPolicy());

            public void onProgressChanged(SeekBar seekBar, final int progress,
                                          boolean fromUser) {
                executor.submit(new Runnable() {
                    @Override
                    public void run() {
                        updateAllViews(progress);
                    }
                });
            }

            public void onStartTrackingTouch(SeekBar seekBar) {
                // Not implemented
            }

            public void onStopTrackingTouch(SeekBar seekBar) {
                // Not implemented
            }
        });

  }

  // Update all Views
    void updateAllViews(int alpha) {
        updateView(mLeftOne, alpha);
    updateView(mLeftTwo, alpha);
    updateView(mRightOne, alpha);
    updateView(mRightThree, alpha);
  }

  // Create a Runnable to execute on the UI Thread
  // When run sets a new color filter on the specified ImageView
  private void updateView(final ImageView image, final int newAlpha) {
    runOnUiThread(new Runnable() {
      public void run() {
        image.setColorFilter(
            Color.argb(newAlpha, MAX_COLOR_COMP, MAX_COLOR_COMP, 0),
            PorterDuff.Mode.ADD);
      }
    });
  }

  // Get references to required Views
  private void initViews() {
    mLeftOne = (ImageView) findViewById(R.id.left_one);
    mLeftTwo = (ImageView) findViewById(R.id.left_two);
    mRightOne = (ImageView) findViewById(R.id.right_one);
    mRightThree = (ImageView) findViewById(R.id.right_three);
  }

  // Create an information PopupWindow
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.options_menu, menu);

    return super.onCreateOptionsMenu(menu);
  }

  // Respond to menu item click
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == R.id.more_info) {
      showDialog();
      return true;
    }
    return super.onOptionsItemSelected(item);
  }

  void showDialog() {
    DialogFragment newFragment = MyAlertDialogFragment.newInstance();
    newFragment.show(getFragmentManager(), "dialog");
  }

  public static class MyAlertDialogFragment extends DialogFragment {

    public static MyAlertDialogFragment newInstance() {
      return new MyAlertDialogFragment();
    }

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {

      // Inflate the popup_layout.xml
      LayoutInflater layoutInflater = (LayoutInflater) getActivity()
          .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

      View myView = layoutInflater.inflate(R.layout.more_info_view, null);

      // Attach listener to "Not Now" Button
      Button dismissButton = (Button) myView
          .findViewById(R.id.dismiss_button);
      dismissButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
          dismiss();
        }
      });

      // Visit MOMA button takes the user to the URL stored in
      // VISIT_MOMA_URL
      Button momaButton = (Button) myView
          .findViewById(R.id.visit_moma_button);
      momaButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
          startActivity(new Intent(Intent.ACTION_VIEW, Uri
              .parse(VISIT_MOMA_URL)));
          dismiss();
        }
      });

      return new AlertDialog.Builder(getActivity()).setView(myView)
          .create();
    }
  }
}




Java Source Code List

com.example.aporter.helloandroidwithimageview.HelloAndroidWithImageViewActivity.java
course.examples.Fragments.DynamicLayout.QuoteViewerActivity.java
course.examples.Fragments.DynamicLayout.QuotesFragment.java
course.examples.Fragments.DynamicLayout.TitlesFragment.java
course.examples.Notification.StatusBarWithCustomView.NotificationSpecialActivity.java
course.examples.Notification.StatusBarWithCustomView.NotificationStatusBarWithExpandedViewActivity.java
course.examples.Notification.Toast.NotificationToastActivity.java
course.examples.Notification.ToastWithCustomView.NotificationToastActivity.java
course.examples.UI.AlertDialog.AlertDialogActivity.java
course.examples.UI.AutoComplete.AutoCompleteActivity.java
course.examples.UI.Button.ButtonActivity.java
course.examples.UI.CheckBox.CheckBoxActivity.java
course.examples.UI.GridView.GridLayoutActivity.java
course.examples.UI.GridView.ImageAdapter.java
course.examples.UI.GridView.ImageViewActivity.java
course.examples.UI.LinearLayout.LinearLayoutActivity.java
course.examples.UI.ListLayout.ListViewActivity.java
course.examples.UI.ListLayout.ListViewAdapter.java
course.examples.UI.MapView.GoogleMapActivity.java
course.examples.UI.RadioGroup.RadioGroupActivity.java
course.examples.UI.RatingsBar.RatingsBarActivity.java
course.examples.UI.RecyclerView.MyRecyclerViewAdapter.java
course.examples.UI.RecyclerView.RecyclerViewActivity.java
course.examples.UI.RelativeLayout.RelativeLayoutActivity.java
course.examples.UI.Spinner.SpinnerActivity.java
course.examples.UI.TabLayout.GridFragment.java
course.examples.UI.TabLayout.ImageAdapter.java
course.examples.UI.TabLayout.ImageViewActivity.java
course.examples.UI.TabLayout.TabLayoutActivity.java
course.examples.UI.TableLayout.TableLayoutActivity.java
course.examples.UI.ViewPager.GalleryWithViewPagerActivity.java
course.examples.UI.ViewPager.ImageAdapter.java
course.examples.UI.ViewPager.ImageHolderFragment.java
course.examples.UI.WebView.WebViewActivity.java
course.examples.UI.datepicker.DatePickerFragmentActivity.java
course.examples.UI.timepicker.TimePickerFragmentActivity.java
course.examples.UI.togglebutton.ToggleButtonActivity.java
course.examples.colorpalettewithnavdrawer.ApplicationTest.java
course.examples.colorpalettewithnavdrawer.DisplayColorActivity.java
course.examples.colorpalettewithnavdrawer.DisplaySingleColorActivity.java
course.examples.colorpalettewithnavdrawer.PaletteNameAdapter.java
course.examples.colorpalettewithswipe.ApplicationTest.java
course.examples.colorpalettewithswipe.DisplayColorPaletteActivity.java
course.examples.colorpalettewithswipe.DisplaySingleColorActivity.java
course.examples.colorpalettewithswipe.PaletteAdapter.java
course.examples.fragments.StaticLayout.QuoteViewerActivity.java
course.examples.fragments.StaticLayout.QuotesFragment.java
course.examples.fragments.StaticLayout.TitlesFragment.java
course.examples.fragments.staticconfiglayout.QuoteViewerActivity.java
course.examples.fragments.staticconfiglayout.QuotesFragment.java
course.examples.fragments.staticconfiglayout.TitlesFragment.java
course.examples.helloandroidwithlogin.ApplicationTest.java
course.examples.helloandroidwithlogin.HelloAndroidWithImageViewActivity.java
course.examples.helloandroidwithlogin.LoginActivity.java
course.examples.modernartpiano.MainActivity.java
course.examples.modernartui.MainActivity.java
course.examples.notification.StatusBar.NotificationStatusBarActivity.java
course.examples.notification.StatusBar.NotificationSubActivity.java
course.examples.quoteviewer.QuoteListActivity.java
course.examples.quoteviewer.TitlesListActivity.java
course.examples.ui.fragmentactionbar.QuoteFragment.java
course.examples.ui.fragmentactionbar.QuoteViewerActivity.java
course.examples.ui.fragmentactionbar.TitlesFragment.java
course.examples.ui.helloworldwithmenus.HelloAndroidWithMenuActivity.java
course.labs.multipane.MainActivity.java
course.labs.multipane.QuoteFragment.java
course.labs.multipane.TitlesFragment.java
course.labs.placebadges.MockLocationProvider.java
course.labs.placebadges.PlaceDownloaderTask.java
course.labs.placebadges.PlaceRecord.java
course.labs.placebadges.PlaceViewActivity.java
course.labs.placebadges.PlaceViewAdapter.java
course.labs.placebadges.PlaceViewDetailActivity.java
course.labs.placebadges_prel.MockLocationProvider.java
course.labs.placebadges_prel.PlaceDownloaderTask.java
course.labs.placebadges_prel.PlaceRecord.java
course.labs.placebadges_prel.PlaceViewActivity.java
course.labs.placebadges_prel.PlaceViewAdapter.java
course.labs.placebadges_prel.PlaceViewDetailActivity.java
examples.course.basiccolorpalette.ApplicationTest.java
examples.course.basiccolorpalette.DisplayColorActivity.java
examples.course.basiccolorpalette.DisplayColorNames.java
examples.course.basiccolorpalette.DisplaySingleColorActivity.java
examples.course.basiccolorpalette.PaletteAdapter.java
examples.course.basiccolorpaletteupnav.ApplicationTest.java
examples.course.basiccolorpaletteupnav.DisplayColorActivity.java
examples.course.basiccolorpaletteupnav.DisplayColorNamesActivity.java
examples.course.basiccolorpaletteupnav.DisplaySingleColorActivity.java
examples.course.basiccolorpaletteupnav.PaletteAdapter.java
examples.course.ticker.TickerDisplayActivity.java
examples.course.uicardview.ApplicationTest.java
examples.course.uicardview.CardViewActivity.java