Example #1
0
  private void updateOrientation() {
    if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {

      int topHeight = getResources().getDisplayMetrics().heightPixels - getPx(150) - getPx(150);

      if (topHeight > getPx(180)) {
        topHeight = (getResources().getDisplayMetrics().heightPixels - getPx(150)) / 2;
      }

      // bottomView.setLayoutParams(new
      // FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, getPx(220), Gravity.BOTTOM));
      pager.setPadding(0, topHeight, 0, getPx(150));

      indicatorContainer.setLayoutParams(
          new FrameLayout.LayoutParams(
              ViewGroup.LayoutParams.MATCH_PARENT, topHeight, Gravity.TOP));
      LinearLayout.LayoutParams params =
          new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, getPx(64));
      params.topMargin = -getPx(4);
      // params.bottomMargin = params.topMargin = getPx(4);
      // params.leftMargin = params.rightMargin = getPx(8);
      openAppButton.setLayoutParams(params);
    } else {
      int topHeight = getResources().getDisplayMetrics().heightPixels - getPx(60) - getPx(150);

      pager.setPadding(0, topHeight, 0, getPx(80));
      indicatorContainer.setLayoutParams(
          new FrameLayout.LayoutParams(
              ViewGroup.LayoutParams.MATCH_PARENT, topHeight, Gravity.TOP));

      //            if (getResources().getDisplayMetrics().heightPixels <= getPx(320)) {
      //                bottomView.setLayoutParams(new
      // FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, getPx(100), Gravity.BOTTOM));
      //            } else {
      //                bottomView.setLayoutParams(new
      // FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, getPx(150), Gravity.BOTTOM));
      //            }

      LinearLayout.LayoutParams params =
          new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, getPx(48));
      params.topMargin = -getPx(4);
      // params.bottomMargin = params.topMargin = getPx(4);
      // params.leftMargin = params.rightMargin = getPx(8);
      openAppButton.setLayoutParams(params);
    }
  }
 /**
  * create ViewPager view</br>
  *
  * @return
  */
 private ViewPager createVIewpager() {
   ViewPager viewPager = new ViewPager(getContext());
   ViewPager.LayoutParams params = new ViewPager.LayoutParams();
   params.width = android.support.v4.view.ViewPager.LayoutParams.MATCH_PARENT;
   params.height = BOARD_HEIGHT;
   viewPager.setLayoutParams(params);
   viewPager.setPadding(0, 15, 0, 0);
   return viewPager;
 }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    overridePendingTransition(R.anim.slide_in_left, R.anim.activity_zoom_exit);

    try {
      ViewConfiguration config = ViewConfiguration.get(this);
      Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey");
      if (menuKeyField != null) {
        menuKeyField.setAccessible(true);
        menuKeyField.setBoolean(config, false);
      }
    } catch (Exception ex) {
      // Ignore
    }

    context = this;
    sharedPrefs =
        context.getSharedPreferences(
            "com.klinker.android.twitter_world_preferences",
            Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE);
    settings = AppSettings.getInstance(this);

    try {
      searchQuery = getIntent().getStringExtra(SearchManager.QUERY);
    } catch (Exception e) {
      searchQuery = "";
    }

    if (searchQuery == null) {
      searchQuery = "";
    }

    handleIntent(getIntent());

    if (Build.VERSION.SDK_INT > 18
        && settings.uiExtras
        && (getResources().getConfiguration().orientation != Configuration.ORIENTATION_LANDSCAPE
            || getResources().getBoolean(R.bool.isTablet))) {
      translucent = true;
      getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);

      try {
        int immersive =
            android.provider.Settings.System.getInt(getContentResolver(), "immersive_mode");

        if (immersive == 1) {
          translucent = false;
        }
      } catch (Exception e) {
      }
    } else {
      translucent = false;
    }

    Utils.setUpTheme(context, settings);
    setContentView(R.layout.search_pager);

    actionBar = getActionBar();
    actionBar.setTitle(getResources().getString(R.string.search));
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setDisplayShowHomeEnabled(true);
    actionBar.setIcon(new ColorDrawable(getResources().getColor(android.R.color.transparent)));

    View statusBar = findViewById(R.id.activity_status_bar);

    mViewPager = (ViewPager) findViewById(R.id.pager);

    if (translucent) {
      statusBar.setVisibility(View.VISIBLE);

      int statusBarHeight = Utils.getStatusBarHeight(context);

      LinearLayout.LayoutParams statusParams =
          (LinearLayout.LayoutParams) statusBar.getLayoutParams();
      statusParams.height = statusBarHeight;
      statusBar.setLayoutParams(statusParams);
    } else {
      mViewPager.setPadding(0, 0, 0, 0);
    }

    mSectionsPagerAdapter =
        new SearchPagerAdapter(
            getFragmentManager(), context, onlyStatus, onlyProfile, searchQuery, translucent);

    mViewPager.setAdapter(mSectionsPagerAdapter);

    mViewPager.setOffscreenPageLimit(3);

    if (settings.addonTheme) {
      PagerTitleStrip strip = (PagerTitleStrip) findViewById(R.id.pager_title_strip);
      strip.setBackgroundColor(settings.pagerTitleInt);
    }

    mViewPager.setCurrentItem(1);

    Utils.setActionBar(context, true);

    if (onlyProfile) {
      mViewPager.setCurrentItem(2);
    }
  }
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);
    View view = inflater.inflate(R.layout.fragment_new_pill, container, false);
    viewPager = (ViewPager) view.findViewById(R.id.pillPager);

    mImages = new ArrayList<Image>();

    Image image = new Image(1, R.drawable.aspirine_blue);
    mImages.add(image);
    image = new Image(2, R.drawable.aspirine_green);
    mImages.add(image);
    image = new Image(3, R.drawable.aspirine_grey);
    mImages.add(image);
    image = new Image(4, R.drawable.aspirine_orange);
    mImages.add(image);
    image = new Image(5, R.drawable.aspirine_purple);
    mImages.add(image);
    image = new Image(6, R.drawable.aspirine_red);
    mImages.add(image);
    image = new Image(7, R.drawable.pill_blue);
    mImages.add(image);
    image = new Image(8, R.drawable.pill_green);
    mImages.add(image);
    image = new Image(9, R.drawable.pill_grey);
    mImages.add(image);
    image = new Image(10, R.drawable.pill_orange);
    mImages.add(image);
    image = new Image(11, R.drawable.pill_purple);
    mImages.add(image);
    image = new Image(12, R.drawable.pill_red);
    mImages.add(image);
    image = new Image(13, R.drawable.container_blue);
    mImages.add(image);
    image = new Image(14, R.drawable.container_green);
    mImages.add(image);
    image = new Image(15, R.drawable.container_grey);
    mImages.add(image);
    image = new Image(16, R.drawable.container_orange);
    mImages.add(image);
    image = new Image(17, R.drawable.container_purple);
    mImages.add(image);
    image = new Image(18, R.drawable.container_red);
    mImages.add(image);

    ImagesPageAdapter adapter = new ImagesPageAdapter(getActivity(), mImages);
    viewPager.setAdapter(adapter);
    viewPager.setClipToPadding(false);
    viewPager.setPadding(80, 0, 80, 0);

    viewPager.setOnPageChangeListener(
        new ViewPager.OnPageChangeListener() {
          @Override
          public void onPageScrolled(
              int position, float positionOffset, int positionOffsetPixels) {}

          @Override
          public void onPageSelected(int position) {}

          @Override
          public void onPageScrollStateChanged(int state) {}
        });

    Button btnSave, btnCancel;

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

          @Override
          public void onClick(View v) {
            int pag = viewPager.getCurrentItem();
            Image image = mImages.get(pag);
            String text = etName.getText().toString();
            if (text.trim().equalsIgnoreCase("")) {
              Toast.makeText(
                      getActivity(),
                      getResources().getString(R.string.new_pill_error_text),
                      Toast.LENGTH_SHORT)
                  .show();
            } else {
              if (pill != null) {
                pill.setmName(text);
                pill.setmImage(image.getrID());
                updatePill();
              } else {
                addPill(text, image.getrID());
              }
              returnBack();
            }
          }
        });

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

          @Override
          public void onClick(View v) {
            returnBack();
          }
        });

    etName = (EditText) view.findViewById(R.id.etName);

    if (pill != null) {
      etName.setText(pill.getmName());

      boolean stop = false;
      int i = 0;
      while (stop == false && i < mImages.size()) {
        Image mImage = mImages.get(i);
        if (mImage.getrID() == pill.getmImage()) {
          stop = true;
          viewPager.setCurrentItem(i, true);
        }
        i++;
      }
    }

    return view;
  }