示例#1
0
文件: EditArticle.java 项目: qyb/sohu
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.edit_article);
    global = (Global) getApplication();
    access_token = global.getAccessToken();
    userid = global.getUserId();
    rapi = new RAPI(this, access_token, userid);

    Bundle bundle = this.getIntent().getExtras();
    type = bundle.getString("type");
    latest = bundle.getString("latest");
    folder_name = bundle.getString("folder_name");

    bookmarkList = (ArrayList<Bookmark>) bundle.getSerializable("bookmark");

    my_category_name = getDefaultCategory(bookmarkList.get(0).getId());
    getAllCategory();
    ensureUi();
  }
示例#2
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.favorites);
    // View view = inflater.inflate(R.layout.favorites, null);
    /*ImageView left = (ImageView) view.findViewById(R.id.favorite_left);
    left.setOnClickListener(new View.OnClickListener() {
    	public void onClick(View v) {
    		//Log.d(TAG, "showLeft");
    		((MainActivity) getActivity()).showLeft();
    	}
    });
    */
    // userid
    userid = Global.getUserId();

    // progressDialog = ProgressDialog.show(getActivity(), "加载中", "请稍后,正在加载...");
    View toastRoot = getLayoutInflater().inflate(R.layout.progressbar_toast, null);
    // progressBar = (ProgressBar)toastRoot.findViewById(R.id.fprogressBar);
    // progressBar.setVisibility(View.VISIBLE);
    LoadingImageView progress = new LoadingImageView(getApplicationContext());
    RelativeLayout rl = (RelativeLayout) toastRoot.findViewById(R.id.progress_toast_layout);
    rl.getBackground().setAlpha(0);
    rl.addView(progress, 84, 84);
    toast = new Toast(getApplicationContext());
    toast.setView(toastRoot);
    toast.setGravity(Gravity.CENTER, 0, 0);
    toast.setDuration(Toast.LENGTH_LONG);
    toast.show();

    buttonRL = (RelativeLayout) findViewById(R.id.fedit);
    deleteButton = (ImageTextButton) findViewById(R.id.fdelete);
    cancelButton = (ImageTextButton) findViewById(R.id.fcancel);
    deleteButton.setImgResource(R.drawable.clip_off);
    deleteButton.setText("限免信息推送");
    cancelButton.setImgResource(R.drawable.pencil);
    cancelButton.setText("编辑");
    deleteButton.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            if (ifdelete) {
              if (!deletefinish) {
                return;
              } else deletefinish = false;
              Log.e(TAG, "deleteinggggggggggggggg");
              NameValuePair pair0, pair1;
              String gameId, cid;
              boolean delete_success = true;
              int selectCount = 0;
              ArrayList<OneGameGame> sub = new ArrayList<OneGameGame>();
              HashMap<Integer, Boolean> allSelected = MyAdapter.getIsSelected();
              for (Integer i = 0; i < list.size(); i++) {
                if (!allSelected.get(i)) continue;
                sub.add(list.get(i));
                selectCount++;
                gameId = String.valueOf(list.get(i).getId());
                cid = String.valueOf(list.get(i).getCollect_num());
                pair0 = new BasicNameValuePair("id", cid);
                pair1 = new BasicNameValuePair("game_id", gameId);
                List<NameValuePair> data = new ArrayList<NameValuePair>();
                data.add(pair0);
                data.add(pair1);
                String str = HttpUtils.doPost(Global.COLLECT_CANCLECOLLECT, data);
                // System.out.println(str);
                try {
                  JSONObject json = new JSONObject(str);
                  String message = json.getString("message");
                  if (!message.equals("success")) delete_success = false;
                  Log.e(TAG, "delete Favorite game message: " + message);

                } catch (JSONException e) {
                  Log.e(TAG, "deleteFavoriteERROR");
                  e.printStackTrace();
                }
              }

              list.removeAll(sub);
              Log.e(
                  "xxxxxxxxxxx",
                  "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx: " + ((Integer) list.size()).toString());
              mAdapter.initData();
              mAdapter.notifyDataSetChanged();

              // View toastRoot = getLayoutInflater().inflate(R.layout.my_toast, null);

              String tv; // TextView tv = (TextView)toastRoot.findViewById(R.id.toast_text);
              if (delete_success) {
                if (selectCount != 0) tv = "删除成功!";
                else tv = "请选择!";
              } else tv = "删除失败!";
              // RelativeLayout rl = (RelativeLayout)toastRoot.findViewById(R.id.toast_layout);
              // rl.getBackground().setAlpha(50);
              Toast mytoast = Toast.makeText(getApplicationContext(), tv, Toast.LENGTH_SHORT);
              // mytoast.setView(toastRoot);
              mytoast.setGravity(Gravity.BOTTOM, 0, 0);
              mytoast.show();
              deletefinish = true;
              Log.e(TAG, "delete finisheddddddd");
            } else {
              Toast mytoast;
              if (isXianMianOn) {
                deleteButton.setImgResource(R.drawable.clip_off);
                mytoast = Toast.makeText(getApplicationContext(), "已关闭", Toast.LENGTH_SHORT);
              } else {
                deleteButton.setImgResource(R.drawable.clip_on);
                mytoast = Toast.makeText(getApplicationContext(), "已打开", Toast.LENGTH_SHORT);
              }

              isXianMianOn = !isXianMianOn;
              mytoast.setGravity(Gravity.BOTTOM, 0, 0);
              mytoast.show();
            }
          }
        });
    cancelButton.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            // handler.sendEmptyMessage(1);
            if (ifcancel) {
              // ArrayList<Integer> selectArr = mAdapter.getAllSelected();
              for (int i = 0; i < mAdapter.getCount(); i++) {
                View temp = favoritesList.getChildAt(i);
                if (temp != null) {
                  ViewHolder viewHolder = (ViewHolder) temp.getTag();
                  // viewHolder.cb.toggle();
                  viewHolder.cb.setVisibility(View.INVISIBLE);
                }
              }
              editmode = false;
              ifcancel = false;
              ifdelete = false;
              deleteButton.setImgResource(R.drawable.clip);
              deleteButton.setText("限免信息推送");
              cancelButton.setText("编辑");
              mAdapter.initData();
              // FavoritesFragment.handl_visible.sendEmptyMessage(0);
            } else {
              for (int i = 0; i < mAdapter.getCount(); i++) {
                View temp = favoritesList.getChildAt(i);
                if (temp != null) {
                  ViewHolder viewHolder = (ViewHolder) temp.getTag();
                  // viewHolder.cb.toggle();
                  viewHolder.cb.setVisibility(View.VISIBLE);
                }
              }
              editmode = true;
              ifcancel = true;
              ifdelete = true;
              deleteButton.setImgResource(R.drawable.delete);
              deleteButton.setText("删除");
              cancelButton.setText("取消编辑");
            }
          }
        });

    /*switcher = (Switch)view.findViewById(R.id.switch1);
    switcher.setOnCheckedChangeListener(new OnCheckedChangeListener(){
              @Override
              public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                  if (isChecked) {
                  	Log.d(TAG, "state is on");
                      //state is on
                  } else {
                  	Log.d(TAG, "state is off");
                      //state is off
                  }
              }
          });*/

    favoritesList = (GridView) findViewById(R.id.favorites_list);
    handl_getdata.sendEmptyMessage(1);
    mAdapter = new MyAdapter(list, favoritesList, getApplicationContext());
    favoritesList.setAdapter(mAdapter);
    favoritesList.setOnItemClickListener(
        new OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            if (editmode) {
              // 取得ViewHolder对象,这样就省去了通过层层的findViewById去实例化我们需要的cb实例的步骤
              ViewHolder holder = (ViewHolder) arg1.getTag();
              // 改变CheckBox的状态
              holder.cb.toggle();
              // 将CheckBox的选中状况记录下来
              // MyAdapter.getIsSelected().put(arg2, holder.cb.isChecked());
            } else {
              OneGameGame game = list.get(arg2);
              Bundle bundle = new Bundle();
              bundle.putSerializable("game", game);
              Intent i = new Intent(getApplicationContext(), DetailActivityForResult.class);
              i.putExtras(bundle);
              startActivity(i);
            }
          }
        });
  }