private void addTabs() {
    ActionBar.Tab addNewExpenseTab = actionBar.newTab();
    addNewExpenseTab.setTabListener(this);
    addNewExpenseTab.setText("Add New");
    actionBar.addTab(addNewExpenseTab);

    ActionBar.Tab todayTab = actionBar.newTab();
    todayTab.setTabListener(this);
    todayTab.setText("Today");
    actionBar.addTab(todayTab);
  }
 private ActionBar.Tab CreateTab(String title, View v) {
   ActionBar actionBar = this.controls.activity.getActionBar();
   ActionBar.Tab tab = actionBar.newTab();
   tab.setText(title); //
   if (mCountTab != 0) {
     v.setVisibility(View.INVISIBLE);
   }
   TabContentFragment content = new TabContentFragment(v, title);
   tab.setTabListener(
       new TabListener(
           content)); // All tabs must have a TabListener set before being added to the ActionBar.
   mCountTab = mCountTab + 1;
   return tab;
 }
 @Override
 public Tab setText(int resId) {
   mNativeTab.setText(resId);
   return this;
 }
 @Override
 public Tab setText(CharSequence text) {
   mNativeTab.setText(text);
   return this;
 }
Esempio n. 5
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    this.getWindow().setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

    setContentView(R.layout.activity_updateshop);

    final ActionBar actionBar = getActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    ActionBar.Tab tab1 = actionBar.newTab();
    tab1.setText("更新")
        .setTabListener(
            new TabListener() {

              @Override
              public void onTabUnselected(Tab tab, FragmentTransaction ft) {}

              @Override
              public void onTabSelected(Tab tab, FragmentTransaction ft) {}

              @Override
              public void onTabReselected(Tab tab, FragmentTransaction ft) {}
            });
    actionBar.addTab(tab1);
    ActionBar.Tab tab2 = actionBar.newTab();
    tab2.setText("削除")
        .setTabListener(
            new TabListener() {

              @Override
              public void onTabUnselected(Tab tab, FragmentTransaction ft) {}

              @Override
              public void onTabSelected(Tab tab, FragmentTransaction ft) {
                AlertDialog.Builder builder = new AlertDialog.Builder(UpdateShopActivity.this);
                builder.setMessage("削除しますか?");
                builder.setPositiveButton(
                    "OK",
                    new DialogInterface.OnClickListener() {

                      @Override
                      public void onClick(DialogInterface dialog, int which) {
                        RamenOpenHelper helper = new RamenOpenHelper(getApplicationContext());
                        SQLiteDatabase db = helper.getReadableDatabase();
                        final RamenDAO dao = new RamenDAO(db);
                        dao.deleteRamenShop(dto_before.getId().toString());
                        Intent intent = new Intent(UpdateShopActivity.this, RamenMapActivity.class);
                        finish();
                        startActivity(intent);
                        Toast.makeText(getApplicationContext(), "削除しました。", Toast.LENGTH_SHORT)
                            .show();
                      }
                    });
                builder.setNegativeButton(
                    "Cancel",
                    new DialogInterface.OnClickListener() {

                      @Override
                      public void onClick(DialogInterface dialog, int which) {
                        actionBar.setSelectedNavigationItem(0);
                      }
                    });
                builder.create().show();
              }

              @Override
              public void onTabReselected(Tab tab, FragmentTransaction ft) {}
            });
    actionBar.addTab(tab2);

    Intent intent = getIntent();
    final String shopid = intent.getStringExtra("shopid");
    RamenOpenHelper helper = new RamenOpenHelper(getApplicationContext());
    SQLiteDatabase db = helper.getWritableDatabase();
    RamenDAO dao = new RamenDAO(db);
    dto_before = dao.findRamenShopById(shopid);

    ((EditText) findViewById(R.id.txt_update_shopname)).setText(dto_before.getName());
    Bitmap bitmap =
        BitmapFactory.decodeByteArray(dto_before.getPict(), 0, dto_before.getPict().length);
    ((ImageView) findViewById(R.id.img_update_ramenpict)).setImageBitmap(bitmap);
    ((EditText) findViewById(R.id.txt_update_lat)).setText(dto_before.getLatitude().toString());
    ((EditText) findViewById(R.id.txt_update_lon)).setText(dto_before.getLongitude().toString());
    ((RatingBar) findViewById(R.id.rat_update_rating)).setRating(dto_before.getRating());
    ((EditText) findViewById(R.id.txt_update_comment)).setText(dto_before.getComment());

    Button btn_takepict = (Button) findViewById(R.id.btn_update_takepict);
    btn_takepict.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View v) {
            locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
            if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
              Toast.makeText(getApplicationContext(), "GPSを利用して現在位置を取得中...", Toast.LENGTH_LONG)
                  .show();
              locationManager.requestLocationUpdates(
                  LocationManager.GPS_PROVIDER, 10000, 0, UpdateShopActivity.this);
            } else if (locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
              Toast.makeText(
                      getApplicationContext(),
                      "GPSが利用できない為Networkを利用して現在位置を取得中...",
                      Toast.LENGTH_LONG)
                  .show();
              locationManager.requestLocationUpdates(
                  LocationManager.NETWORK_PROVIDER, 10000, 0, UpdateShopActivity.this);
            } else {
              Toast.makeText(
                      getApplicationContext(), "GPS及びNetworkが利用出来ない為現在位置の反映なし", Toast.LENGTH_LONG)
                  .show();
              Intent intent = new Intent();
              intent.setAction(MediaStore.ACTION_IMAGE_CAPTURE);
              startActivityForResult(intent, REQUEST_GALLERY_CODE);
            }
          }
        });

    Button btn_selectpict = (Button) findViewById(R.id.btn_update_selectpict);
    btn_selectpict.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View v) {
            Intent intent = new Intent();
            intent.setType("image/*");
            intent.setAction(Intent.ACTION_GET_CONTENT);
            startActivityForResult(intent, REQUEST_GALLERY_CODE);
          }
        });

    Button btn_rotate = (Button) findViewById(R.id.btn_update_rotate);
    btn_rotate.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View v) {
            ImageView imageView = (ImageView) findViewById(R.id.img_update_ramenpict);
            Bitmap bitmap = ((BitmapDrawable) imageView.getDrawable()).getBitmap();
            Matrix mat = new Matrix();
            mat.postRotate(-90);
            imageView.setImageBitmap(
                Bitmap.createBitmap(
                    bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), mat, true));
          }
        });

    Button btn_inputmap = (Button) findViewById(R.id.btn_update_inputmap);
    btn_inputmap.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View v) {
            Toast.makeText(getApplicationContext(), "未実装", Toast.LENGTH_SHORT).show();
          }
        });

    Button btn_submit = (Button) findViewById(R.id.btn_update_submit);
    btn_submit.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View v) {
            String shopname =
                ((EditText) findViewById(R.id.txt_update_shopname)).getText().toString();
            Bitmap shopbitmap =
                ((BitmapDrawable)
                        ((ImageView) findViewById(R.id.img_update_ramenpict)).getDrawable())
                    .getBitmap();
            String shoplat = ((EditText) findViewById(R.id.txt_update_lat)).getText().toString();
            String shoplon = ((EditText) findViewById(R.id.txt_update_lon)).getText().toString();
            int shoprating = (int) ((RatingBar) findViewById(R.id.rat_update_rating)).getRating();
            String shopcomment =
                ((EditText) findViewById(R.id.txt_update_comment)).getText().toString();

            boolean hasErrorInput = false;
            if ("".equals(shopname)) {
              ((EditText) findViewById(R.id.txt_update_shopname)).setError("店名は必須入力です。");
              hasErrorInput = true;
            }
            if ("".equals(shoplat)) {
              ((EditText) findViewById(R.id.txt_update_lat)).setError("経度は必須入力です。");
              hasErrorInput = true;
            }
            if ("".equals(shoplon)) {
              ((EditText) findViewById(R.id.txt_update_lon)).setError("緯度は必須入力です。");
              hasErrorInput = true;
            }

            if (hasErrorInput) {
              Toast.makeText(getApplicationContext(), "入力情報に不備があります。", Toast.LENGTH_LONG).show();
            } else {
              RamenShopDTO dto = new RamenShopDTO();
              dto.setName(shopname);
              dto.setLatitude(Double.valueOf(shoplat));
              dto.setLongitude(Double.valueOf(shoplon));
              dto.setRating(shoprating);
              dto.setComment(shopcomment);
              dto.setId(dto_before.getId());

              ByteArrayOutputStream stream = new ByteArrayOutputStream();
              shopbitmap.compress(Bitmap.CompressFormat.PNG, 90, stream);
              dto.setPict(stream.toByteArray());

              RamenOpenHelper helper = new RamenOpenHelper(getApplicationContext());
              SQLiteDatabase db = helper.getWritableDatabase();
              RamenDAO dao = new RamenDAO(db);
              dao.updateRamenShop(dto);
              Toast.makeText(getApplicationContext(), "更新が完了しました。", Toast.LENGTH_LONG).show();

              Intent intent = new Intent(UpdateShopActivity.this, RamenMapActivity.class);
              intent.putExtra("lat", dto.getLatitude());
              intent.putExtra("lon", dto.getLongitude());
              finish();
              startActivity(intent);
            }
          }
        });
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.workout_info_pager);
    dayWeek = new int[2];

    uDBTools = new UserInfoDatabaseTools(this);

    progress = new ProgressDialog(TrainerDay.this, R.style.MyTheme);
    progress.setCancelable(false);
    progress.setProgressStyle(android.R.style.Widget_ProgressBar_Small);
    progress.show();

    Intent intent = getIntent();

    trainerType = intent.getStringExtra("trainerType");
    dayWeek = intent.getIntArrayExtra("dayWeek");

    viewPager = (ViewPager) findViewById(R.id.workout_view_pager);
    viewPager.setOffscreenPageLimit(2);

    myAdapter = new MyAdapter(getSupportFragmentManager());

    viewPager.setAdapter(myAdapter);
    viewPager.setOnPageChangeListener(
        new ViewPager.OnPageChangeListener() {

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

          @Override
          public void onPageSelected(int position) {
            actionBar.setSelectedNavigationItem(position);
            Fragment page =
                getSupportFragmentManager()
                    .findFragmentByTag(
                        "android:switcher:"
                            + R.id.workout_view_pager
                            + ":"
                            + viewPager.getCurrentItem());

            if (viewPager.getCurrentItem() == 1 && page != null) {
              ((TrainerWorkoutTab) page).updateFragment();
            }
          }

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

    actionBar = this.getActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    formatTab = actionBar.newTab();
    formatTab.setText("WarmUp");
    formatTab.setTabListener(this);

    wallTab = actionBar.newTab();
    wallTab.setText("Workout");
    wallTab.setTabListener(this);

    postTab = actionBar.newTab();
    postTab.setText("Stretch/Core");
    postTab.setTabListener(this);

    actionBar.addTab(formatTab);
    actionBar.addTab(wallTab);
    actionBar.addTab(postTab);
  }