Android Open Source - Alfred4Android Expression






From Project

Back to project page Alfred4Android.

License

The source code is released under:

Apache License

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

package com.toraleap.collimator.data;
/*from  www  .  j  ava 2  s.  c o m*/
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

import org.json.JSONException;
import org.json.JSONObject;

import android.content.Context;

import com.toraleap.collimator.R;

/**
 * ?????????????????????????????????????????????????JSON????????????JSON??????????
 * @author    uestc.Mobius <mobius@toraleap.com>
 * @version  2010.1015
 */
public final class Expression {
  private Context mContext;
  private int mRange;
  private int mSortMode = Sorter.SORT_DATE;
  private boolean mSortReverse = true;
  private String mKey = "";
  private String mName;
  
  /**
   * ???????????????????
   * @param context  ???????????
   */
  public Expression(Context context) { 
    mContext = context;
  }
  
  /**
   * ?????JSON???????????????????
   * @param context  ???????????
   * @param json    JSON?????????
   */
  public Expression(Context context, String json) {
    this(context);
    try {
      JSONObject obj = new JSONObject(json);
      mName = obj.optString("name");
      mRange = obj.optInt("range");
      mSortMode = obj.optInt("sortMode");
      mSortReverse = obj.optBoolean("sortReverse");
      mKey = obj.optString("key");
    } catch (JSONException e) {
      e.printStackTrace();
    }
  }
  
  /**
   * ?????????????????
   * @return ?????
   */
  public Comparator<Match> getSorter() {
    return Sorter.getSorter(mSortMode, mSortReverse);
  }
  
  /**
   * ????????????????(???????Sorter????)??
   * @return ?????????
   */
  public int getSortMode() {
    return mSortMode;
  }
  
  /**
   * ?????????????????
   * @return ?????
   */
  public boolean getSortReverse() {
    return mSortReverse;
  }
  
  /**
   * ??????????????????(???array.xml??)??
   * @return ???????????
   */
  public int getRange() {
    return mRange;
  }
  
  /**
   * ?????????????????????
   * @return ??????????
   */
  public String getKey() {
    return mKey;
  }
  
  /**
   * ????????????????
   * @return ?????????
   */
  public String getName() {
    if (mName == null) return mKey;
    return mName;
  }
  
  /**
   * ?????????????????
   * @param sortMode ?????(???????Sorter????)
   * @param reverse  ?????
   */
  public void setSort(int sortMode, boolean reverse) {
    mSortMode = sortMode;
    mSortReverse = reverse;
  }
  
  /**
   * ?????????????????
   * @param sortMode ?????(???????Sorter????)
   */
  public void setSort(int sortMode) {
    mSortMode = sortMode;
  }
  
  /**
   * ?????????????????
   * @param reverse  ?????
   */
  public void setSort(boolean reverse) {
    mSortReverse = reverse;
  }
  
  /**
   * ?????????????????(???array.xml??)??
   * @param range    ???????????
   */
  public void setRange(int range) {
    mRange = range;
  }
  
  /**
   * ????????????????????
   * @param key  ??????????
   */
  public void setKey(String key) {
    mKey = key;
  }
  
  /**
   * ???????????????
   * @return ?????????
   */
  public void setName(String name) {
    mName = name;
  }
  
  /**
   * ??????????????????????????????????????? Matcher ??????????????????????????????? Matcher.init ???????????????????????????????????????????????????????????????????????
   */
  public void matchAsync() {
    Matcher.matchAsync(matchers());
  }
  
  /**
   * ??????????????????????????? Matcher ????????????????????????????????? Matcher ????????? null??
   * @return ???????? Matcher ???? ?? null
   */
  public Matcher[] matchers() {
    String[] keys = mKey.split(" ");
    List<Matcher> matchers = new ArrayList<Matcher>(keys.length + 1);
    try {
      if (mRange > 0) {
        matchers.add(new Matcher(mContext.getResources().getStringArray(R.array.dialog_filter_range_entriesvalue)[mRange]));
      }
      for (int i = 0; i < keys.length; i++) {
        matchers.add(new Matcher(keys[i]));
      }
      return matchers.toArray(new Matcher[matchers.size()]);
    } catch (Exception e) {
      e.printStackTrace();
      return null;
    }
  }
  
  /**
   * ???????????JSON??????????????
   * @return JSON?????????
   */
  public String toJSON() {
    JSONObject obj = new JSONObject();
    try {
      obj.put("name", mName);
      obj.put("range", mRange);
      obj.put("sortMode", mSortMode);
      obj.put("sortReverse", mSortReverse);
      obj.put("key", mKey);
    } catch (JSONException e) {
      e.printStackTrace();
    }
    return obj.toString();
  }
}




Java Source Code List

android.media.MediaMetadataRetriever.java
com.toraleap.collimator.AppSearchActivity.java
com.toraleap.collimator.GlobalContext.java
com.toraleap.collimator.HelpActivity.java
com.toraleap.collimator.PrefsActivity.java
com.toraleap.collimator.SearchActivity.java
com.toraleap.collimator.ShortcutActivity.java
com.toraleap.collimator.bll.FileScannerService.java
com.toraleap.collimator.bll.TagGenerator.java
com.toraleap.collimator.dal.DBColumns.java
com.toraleap.collimator.dal.DBHelper.java
com.toraleap.collimator.dal.DBOperation.java
com.toraleap.collimator.data.Expression.java
com.toraleap.collimator.data.IndexData.java
com.toraleap.collimator.data.IndexLoader.java
com.toraleap.collimator.data.Index.java
com.toraleap.collimator.data.Match.java
com.toraleap.collimator.data.Matcher.java
com.toraleap.collimator.data.Sorter.java
com.toraleap.collimator.ext.GlobalProvider.java
com.toraleap.collimator.ext.Playlist.java
com.toraleap.collimator.model.BaseTag.java
com.toraleap.collimator.ui.FloatingDialog.java
com.toraleap.collimator.ui.MatchAdapter.java
com.toraleap.collimator.util.DigestUtil.java
com.toraleap.collimator.util.FileInfo.java
com.toraleap.collimator.util.MimeTypeMap.java
com.toraleap.collimator.util.RecursiveFileObserver.java
com.toraleap.collimator.util.ShortcutHelper.java
com.toraleap.collimator.util.SoftCache.java
com.toraleap.collimator.util.ThumbnailUtil.java
com.toraleap.collimator.util.Unicode2Alpha.java