Esempio n. 1
0
  /** Called when the activity is first created */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    Log.d(TAG, "LoaderActivity created");
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.content);

    // Instantiate custom adapter
    mAdapter = new LoaderAdapter();

    // Handle listview and assign adapter
    mListView = (ListView) findViewById(R.id.content_list_view);
    mListView.setAdapter(mAdapter);
    mListView.setVisibility(View.GONE);
    mListView.setOnItemLongClickListener(
        new AdapterView.OnItemLongClickListener() {
          public boolean onItemLongClick(AdapterView parent, View view, int position, long id) {
            selectItem(position);
            return true;
          }
        });

    mStatusLabel = (TextView) findViewById(R.id.content_status_label);
    mStatusLabel.setVisibility(View.VISIBLE);

    String userHash = NavigineApp.Settings.getString("user_hash", "");
    if (userHash.length() == 0) showUserHashDialog();
    else refreshMapList();
  }
  private void init() {
    setVerticalFadingEdgeEnabled(false);

    headerContainer =
        (LinearLayout) LayoutInflater.from(getContext()).inflate(R.layout.ptr_header, null);
    header = (RelativeLayout) headerContainer.findViewById(R.id.ptr_id_header);
    text = (TextView) header.findViewById(R.id.ptr_id_text);
    lastUpdatedTextView = (TextView) header.findViewById(R.id.ptr_id_last_updated);
    image = (ImageView) header.findViewById(R.id.ptr_id_image);
    spinner = (ProgressBar) header.findViewById(R.id.ptr_id_spinner);

    pullToRefreshText = getContext().getString(R.string.ptr_pull_to_refresh);
    releaseToRefreshText = getContext().getString(R.string.ptr_release_to_refresh);
    refreshingText = getContext().getString(R.string.ptr_refreshing);
    lastUpdatedText = getContext().getString(R.string.ptr_last_updated);

    flipAnimation =
        new RotateAnimation(
            0,
            -180,
            RotateAnimation.RELATIVE_TO_SELF,
            0.5f,
            RotateAnimation.RELATIVE_TO_SELF,
            0.5f);
    flipAnimation.setInterpolator(new LinearInterpolator());
    flipAnimation.setDuration(ROTATE_ARROW_ANIMATION_DURATION);
    flipAnimation.setFillAfter(true);

    reverseFlipAnimation =
        new RotateAnimation(
            -180,
            0,
            RotateAnimation.RELATIVE_TO_SELF,
            0.5f,
            RotateAnimation.RELATIVE_TO_SELF,
            0.5f);
    reverseFlipAnimation.setInterpolator(new LinearInterpolator());
    reverseFlipAnimation.setDuration(ROTATE_ARROW_ANIMATION_DURATION);
    reverseFlipAnimation.setFillAfter(true);

    addHeaderView(headerContainer);
    setState(State.PULL_TO_REFRESH);
    scrollbarEnabled = isVerticalScrollBarEnabled();

    ViewTreeObserver vto = header.getViewTreeObserver();
    vto.addOnGlobalLayoutListener(new PTROnGlobalLayoutListener());

    super.setOnItemClickListener(new PTROnItemClickListener());
    super.setOnItemLongClickListener(new PTROnItemLongClickListener());
  }
Esempio n. 3
0
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.record_journal);
    Bundle bundle = getIntent().getExtras();
    String journalIDs = (String) bundle.get("journals");
    String recordID = (String) bundle.get("recordID");
    myJournalNetwork.requestList(journalIDs, recordID);
    final ArrayList<HashMap<String, String>> journalList = myJournalNetwork.getList();

    ListView listView = (ListView) findViewById(R.id.record_journal_listView);
    record_journal_adapter = new Record_Journal_Adapter(this, journalList);
    listView.setAdapter(record_journal_adapter);
    listView.setOnItemClickListener(
        new AdapterView.OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            // To change body of implemented methods use File | Settings | File Templates.
            // LayoutInflater inflater = (LayoutInflater)
            // Record_Journal.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            final int position = i;
            final HashMap<String, String> modified_journal = journalList.get(i);
            LayoutInflater inflater = LayoutInflater.from(adapterView.getContext());
            LinearLayout linearLayout =
                (LinearLayout) inflater.inflate(R.layout.journal_clickitem, null);
            AlertDialog.Builder builder = new AlertDialog.Builder(Record_Journal.this);

            // String type = (String) ((HashMap<String,
            // Object>)adapterView.getAdapter().getItem(i)).get("type");
            TextView titleTextView = (TextView) view.findViewById(R.id.journal_title_textView);
            String title = (String) titleTextView.getText();

            TextView contentTextView = (TextView) view.findViewById(R.id.journal_content_textView);
            String content = (String) contentTextView.getText();

            final EditText titleEditText =
                (EditText) linearLayout.findViewById(R.id.journal_title_editText);
            titleEditText.setText(title);

            final EditText contentEditText =
                (EditText) linearLayout.findViewById(R.id.journal_content_editText);
            contentEditText.setText(content);

            titleEditText.setEnabled(true);
            contentEditText.setEnabled(true);

            builder.setPositiveButton(
                "保 存",
                new DialogInterface.OnClickListener() {
                  @Override
                  public void onClick(DialogInterface dialogInterface, int i) {
                    // To change body of implemented methods use File | Settings | File Templates.
                    modified_journal.put("title", String.valueOf(titleEditText.getText()));
                    modified_journal.put("body", String.valueOf(contentEditText.getText()));
                    String date =
                        String.valueOf(new SimpleDateFormat("yyyy-MM-dd").format(new Date()));
                    modified_journal.put("time", date);
                    modified_journal.put("userID", Login.userID);
                    if (myJournalNetwork.modify(position, modified_journal)) {
                      Toast.makeText(Record_Journal.this, "修改成功", Toast.LENGTH_SHORT);
                    } else {
                      Toast.makeText(Record_Journal.this, "修改失败", Toast.LENGTH_SHORT);
                    }
                    record_journal_adapter.notifyDataSetChanged();
                  }
                });
            builder.setNegativeButton(
                "取 消",
                new DialogInterface.OnClickListener() {
                  @Override
                  public void onClick(DialogInterface dialogInterface, int i) {
                    // To change body of implemented methods use File | Settings | File Templates.
                  }
                });

            builder.setTitle("编辑日志").setView(linearLayout);
            builder.show();
          }
        });
    listView.setOnItemLongClickListener(
        new AdapterView.OnItemLongClickListener() {
          @Override
          public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long l) {
            // TODO delete journal
            return false; // To change body of implemented methods use File | Settings | File
                          // Templates.
          }
        });
  }