Android Open Source - ShareSDK-for-Android Custom Share Fields Page






From Project

Back to project page ShareSDK-for-Android.

License

The source code is released under:

MIT License

If you think the Android project ShareSDK-for-Android 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

/*
 * Copyright (c) Mob.COM $year.14-10-27 ????4:01
 */* w  w  w  .  j  a v a2  s .  c o  m*/
 * @author Milk <jecelyin@gmail.com>
 */

package cn.sharesdk.demo;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;

import java.util.HashMap;

import cn.sharesdk.framework.TitleLayout;
import m.framework.ui.widget.slidingmenu.SlidingMenu;

/**
 * @author Jecelyin <jecelyin@gmail.com>
 * @since 2014.10.27
 */
public class CustomShareFieldsPage extends SlidingMenuPage implements View.OnClickListener, AdapterView.OnItemClickListener {
  private final TitleLayout llTitle;
  private final static String[] KEYS = {
      "enableSSO(1,0)"
      ,"theme(classic,skyblue)"
      ,"title"
      ,"titleUrl"
      ,"text"
      ,"imagePath"
      ,"imageUrl"
      ,"url"
      ,"filePath"
      ,"comment"
      ,"site"
      ,"siteUrl"
      ,"venueName"
      ,"venueDescription"
  };
  private final static HashMap<String, String> storeMap = new HashMap<String, String>(KEYS.length);
  private final CustomFieldsAdapter adapter;

  public static String getString(String key, String def) {
    if(storeMap.containsKey(key))
      return storeMap.get(key);
    return def;
  }

  public static boolean getBoolean(String key, boolean def) {
    if(storeMap.containsKey(key))
    {
      String val = storeMap.get(key).trim();
      return "1".equals(val) || "yes".equals(val) || "true".equals(val);
    }
    return def;
  }

  private static void setString(String key, String value) {
    storeMap.put(key, value);
  }

  public CustomShareFieldsPage(SlidingMenu menu) {
    super(menu);
    View pageView = getPage();
    llTitle = (TitleLayout) pageView.findViewById(R.id.llTitle);
    llTitle.getBtnBack().setOnClickListener(this);
    llTitle.getTvTitle().setText(R.string.sm_item_custom_fields);

    adapter = new CustomFieldsAdapter(getContext().getApplicationContext());
    ListView listView = (ListView)pageView.findViewById(R.id.listView);
    listView.setAdapter(adapter);
    listView.setOnItemClickListener(this);
  }

  @Override
  protected View initPage() {
    return View.inflate(getContext(), R.layout.page_custom_fields, null);
  }

  @Override
  public void onClick(View v) {
    if (v.equals(llTitle.getBtnBack())) {
      if (isMenuShown()) {
        hideMenu();
      }
      else {
        showMenu();
      }
    }
  }

  @Override
  public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    final String key = KEYS[position];
    String value = (String) adapter.getItem(position);

    AlertDialog.Builder alert = new AlertDialog.Builder(getContext());
    alert.setMessage(key + " :");

    // Set an EditText view to get user input
    final EditText editText = new EditText(getContext());
    editText.setText(value);
    alert.setView(editText);

    alert.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
      public void onClick(DialogInterface dialog, int whichButton) {
        String newValue = editText.getText().toString().trim();
        setString(key.replaceAll("\\(.+?\\)", ""), newValue);
        dialog.dismiss();
        adapter.notifyDataSetChanged();
      }
    });

    alert.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {

      public void onClick(DialogInterface dialog, int which) {
        dialog.dismiss();
      }
    });
    alert.show();
  }

  private static class CustomFieldsAdapter extends BaseAdapter {

    private final Context context;

    public CustomFieldsAdapter(Context context) {
      this.context = context;
    }

    @Override
    public int getCount() {
      return KEYS.length;
    }

    @Override
    public Object getItem(int position) {
      return getString(KEYS[position].replaceAll("\\(.+?\\)",""), "");
    }

    @Override
    public long getItemId(int position) {
      return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
      TextView keyTextView, valueTextView;
      if(convertView == null) {
        convertView = LayoutInflater.from(context).inflate(R.layout.page_custom_fields_item, null);
        keyTextView = (TextView) convertView.findViewById(R.id.keyTextView);
        valueTextView = (TextView) convertView.findViewById(R.id.valueTextView);
        convertView.setTag(R.id.keyTextView, keyTextView);
        convertView.setTag(R.id.valueTextView, valueTextView);
      }else{
        keyTextView = (TextView) convertView.getTag(R.id.keyTextView);
        valueTextView = (TextView) convertView.getTag(R.id.valueTextView);
      }

      keyTextView.setText(KEYS[position]);
      valueTextView.setText((String)getItem(position));

      return convertView;
    }
  }
}




Java Source Code List

cn.sharesdk.demo.AuthPage.java
cn.sharesdk.demo.CustomShareFieldsPage.java
cn.sharesdk.demo.CustomerPage.java
cn.sharesdk.demo.DemoPage.java
cn.sharesdk.demo.GetInforPage.java
cn.sharesdk.demo.GetTokenPage.java
cn.sharesdk.demo.JsonPage.java
cn.sharesdk.demo.Laiwang.java
cn.sharesdk.demo.MainActivity.java
cn.sharesdk.demo.MainAdapter.java
cn.sharesdk.demo.MyAdapter.java
cn.sharesdk.demo.MyQZoneWebShareAdapter.java
cn.sharesdk.demo.OneKeyShareCallback.java
cn.sharesdk.demo.ShareContentCustomizeDemo.java
cn.sharesdk.demo.SlidingMenuPage.java
cn.sharesdk.demo.WechatPage.java
cn.sharesdk.demo.YixinPage.java
cn.sharesdk.demo.wxapi.WXEntryActivity.java
cn.sharesdk.demo.yxapi.YXEntryActivity.java
cn.sharesdk.onekeyshare.CustomerLogo.java
cn.sharesdk.onekeyshare.CustomerLogo.java
cn.sharesdk.onekeyshare.EditPageFakeActivity.java
cn.sharesdk.onekeyshare.EditPageFakeActivity.java
cn.sharesdk.onekeyshare.FollowerListFakeActivity.java
cn.sharesdk.onekeyshare.FollowerListFakeActivity.java
cn.sharesdk.onekeyshare.OnekeyShareTheme.java
cn.sharesdk.onekeyshare.OnekeyShareTheme.java
cn.sharesdk.onekeyshare.OnekeyShare.java
cn.sharesdk.onekeyshare.OnekeyShare.java
cn.sharesdk.onekeyshare.PicViewer.java
cn.sharesdk.onekeyshare.PicViewer.java
cn.sharesdk.onekeyshare.PlatformListFakeActivity.java
cn.sharesdk.onekeyshare.PlatformListFakeActivity.java
cn.sharesdk.onekeyshare.Shake2Share.java
cn.sharesdk.onekeyshare.Shake2Share.java
cn.sharesdk.onekeyshare.ShareContentCustomizeCallback.java
cn.sharesdk.onekeyshare.ShareContentCustomizeCallback.java
cn.sharesdk.onekeyshare.ShareCore.java
cn.sharesdk.onekeyshare.ShareCore.java
cn.sharesdk.onekeyshare.ThemeShareCallback.java
cn.sharesdk.onekeyshare.ThemeShareCallback.java
cn.sharesdk.onekeyshare.theme.classic.EditPage.java
cn.sharesdk.onekeyshare.theme.classic.EditPage.java
cn.sharesdk.onekeyshare.theme.classic.FollowListPage.java
cn.sharesdk.onekeyshare.theme.classic.FollowListPage.java
cn.sharesdk.onekeyshare.theme.classic.PlatformGridView.java
cn.sharesdk.onekeyshare.theme.classic.PlatformGridView.java
cn.sharesdk.onekeyshare.theme.classic.PlatformListPage.java
cn.sharesdk.onekeyshare.theme.classic.PlatformListPage.java
cn.sharesdk.onekeyshare.theme.skyblue.EditPage.java
cn.sharesdk.onekeyshare.theme.skyblue.EditPage.java
cn.sharesdk.onekeyshare.theme.skyblue.FollowListPage.java
cn.sharesdk.onekeyshare.theme.skyblue.FollowListPage.java
cn.sharesdk.onekeyshare.theme.skyblue.PlatformGridViewAdapter.java
cn.sharesdk.onekeyshare.theme.skyblue.PlatformGridViewAdapter.java
cn.sharesdk.onekeyshare.theme.skyblue.PlatformListPage.java
cn.sharesdk.onekeyshare.theme.skyblue.PlatformListPage.java
cn.sharesdk.socialization.sample.MainActivity.java
cn.sharesdk.socialization.sample.MyPlatform.java
cn.sharesdk.socialization.sample.wxapi.WXEntryActivity.java
cn.sharesdk.socialization.sample.yxapi.YXEntryActivity.java