当前位置:  编程技术>移动开发
本页文章导读:
    ▪lucene 排序,过滤,高亮展示        lucene 排序,过滤,高亮显示   package com.nanjing.chaoxing.lucene; import com.nanjing.chaoxing.lucene.model.Book; import com.nanjing.chaoxing.lucene.model.BookUtil; import org.apache.log4j.Logger; import org.apache.lucene.analysis.standard.Sta.........
    ▪ IdentifyTask-因素识别 -长按某一点后查询,并将查询结果高亮显示        IdentifyTask--要素识别 ----长按某一点后查询,并将查询结果高亮显示 public class HighlightFeatures extends Activity { private MapView mapView; private ArcGISTiledMapServiceLayer tiledMapServiceLayer; private GraphicsLayer g.........
    ▪ alertdialog 应用系统选择时改变 默认字体大小       alertdialog 使用系统选择时改变 默认字体大小 ContextThemeWrapper ctw = new ContextThemeWrapper( getActivity(), R.style.AlertDialogCustom ); Builder builder = new AlertDialog.Builder(btw); <style name="AlertDialogCustom" parent=.........

[1]lucene 排序,过滤,高亮展示
    来源: 互联网  发布时间: 2014-02-18
lucene 排序,过滤,高亮显示

 

package com.nanjing.chaoxing.lucene;

import com.nanjing.chaoxing.lucene.model.Book;
import com.nanjing.chaoxing.lucene.model.BookUtil;
import org.apache.log4j.Logger;
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.queryParser.ParseException;
import org.apache.lucene.queryParser.QueryParser;
import org.apache.lucene.search.*;
import org.apache.lucene.search.highlight.*;
import org.apache.lucene.search.highlight.Scorer;
import org.apache.lucene.store.FSDirectory;
import org.apache.lucene.util.Version;
import org.junit.BeforeClass;
import org.junit.Test;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class SortAndFilterAndHighligher {
    private Logger logger = Logger.getLogger(SortAndFilterAndHighligher.class);

    @BeforeClass
    public static void init() throws IOException {
        BookUtil bookUtil = new BookUtil();
        bookUtil.createIndexWriter();
        bookUtil.createDocument();
    }

    /**
     * 排序并过滤
     * @throws IOException
     * @throws ParseException
     */
    @Test
    public void sort() throws IOException, ParseException {
        IndexReader indexReader = IndexReader.open(FSDirectory.open(BookUtil.indexFile));
        Query query = new QueryParser(Version.LUCENE_36, "bookid", new StandardAnalyzer(Version.LUCENE_36)).parse("6270000~");
        IndexSearcher indexSearcher = new IndexSearcher(indexReader);
        //数字过滤器
        NumericRangeFilter numericRangeFilter = NumericRangeFilter.newIntRange("year", 2010, 2012, true, true);
        //排序
        SortField sortField = new SortField("bookid", SortField.STRING);

        logger.info("sort" + " begin....");
        TopDocs topDocs = indexSearcher.search(query, numericRangeFilter, 1000, new Sort(sortField));
        ScoreDoc[] scoreDocs = topDocs.scoreDocs;
        for (int i = 0; i < scoreDocs.length; i++) {
            ScoreDoc scoreDoc = scoreDocs[i];
            int doc = scoreDoc.doc;
            for (Book book : BookUtil.bookList) {
                if (indexSearcher.doc(doc).get("bookid").equals(book.getBookid())) {
                    logger.info(book.toString());
                }
            }
        }
        logger.info("sort" + " end....\n");
    }


    /**
     * 高亮显示
     *
     * @throws ParseException
     * @throws IOException
     */
//    @Test
    public void highligher() throws ParseException, IOException, InvalidTokenOffsetsException {
        List<Book> books = new ArrayList<Book>();
        IndexReader indexReader = IndexReader.open(FSDirectory.open(BookUtil.indexFile));
        Query query = new QueryParser(Version.LUCENE_36, "author", new StandardAnalyzer(Version.LUCENE_36)).parse("jam~");
        IndexSearcher indexSearcher = new IndexSearcher(indexReader);
        SimpleHTMLFormatter simpleHTMLFormatter = new SimpleHTMLFormatter("<font color='red'>", "</font>");
        Scorer scorer = new QueryScorer(query);
        Highlighter highlighter = new Highlighter(simpleHTMLFormatter, scorer);
        Fragmenter fragmenter = new SimpleFragmenter(100);
        highlighter.setTextFragmenter(fragmenter);

        TopDocs topDocs = indexSearcher.search(query, 1000);
        ScoreDoc[] scoreDocs = topDocs.scoreDocs;
        System.out.println("高亮显示:");
        for (int i = 0; i < scoreDocs.length; i++) {
            int docid = scoreDocs[i].doc;
            float score = scoreDocs[i].score;//当前结果的相关度得分
            System.out.println("score is : " + score);
            Document doc = indexSearcher.doc(docid);
            String author = doc.get("author");
            String highterBooid = highlighter.getBestFragment(new StandardAnalyzer(Version.LUCENE_36), "author", author);
            for (Book book : BookUtil.bookList) {
                if (book.getBookid().equals(doc.get("bookid"))) {
                    book.setAuthor(highterBooid);
                    System.out.println(book.toString());
                }
            }
        }

    }
}

    
[2] IdentifyTask-因素识别 -长按某一点后查询,并将查询结果高亮显示
    来源: 互联网  发布时间: 2014-02-18
IdentifyTask--要素识别 ----长按某一点后查询,并将查询结果高亮显示

public class HighlightFeatures extends Activity {

	private MapView mapView;
	private ArcGISTiledMapServiceLayer tiledMapServiceLayer;
	private GraphicsLayer graphicsLayer;
	private Graphic[] highlightGraphics;

	private String mapURL = "http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/PublicSafety/PublicSafetyBasemap/MapServer";

	@SuppressWarnings("serial")
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setContentView(R.layout.main);

		mapView = (MapView) findViewById(R.id.map);
		mapView.setOnLongPressListener(new OnLongPressListener() {
			public void onLongPress(float x, float y) {
				identifyPoint(x, y);
			}
		});

		tiledMapServiceLayer = new ArcGISTiledMapServiceLayer(mapURL);
		graphicsLayer = new GraphicsLayer();

		mapView.addLayer(tiledMapServiceLayer);
		mapView.addLayer(graphicsLayer);
	}

	// 要素识别长按点
	protected void identifyPoint(float x, float y) {
		try {
			graphicsLayer.removeAll();
			Point pointClicked = mapView.toMapPoint(x, y);

			IdentifyParameters params = new IdentifyParameters();
			params.setGeometry(pointClicked);
			params.setLayers(new int[] { 28 });
			Envelope env = new Envelope();
			mapView.getExtent().queryEnvelope(env);
			params.setSpatialReference(mapView.getSpatialReference());
			params.setMapExtent(env);
			params.setDPI(96);
			params.setMapHeight(mapView.getHeight());
			params.setMapWidth(mapView.getWidth());
			params.setTolerance(10);

			// 执行查询任务
			MyIdentifyTask mIdenitfy = new MyIdentifyTask();
			mIdenitfy.execute(params);

		} catch (Exception ex) {
			ex.printStackTrace();
		}

	}

	@Override
	protected void onPause() {
		super.onPause();
		mapView.pause();
	}

	@Override
	protected void onResume() {
		super.onResume();
		mapView.unpause();
	}

	private class MyIdentifyTask extends
			AsyncTask<IdentifyParameters, Void, IdentifyResult[]> {

		IdentifyTask mIdentifyTask;

		@Override
		protected IdentifyResult[] doInBackground(IdentifyParameters... params) {
			IdentifyResult[] mResult = null;
			if (params != null && params.length > 0) {
				IdentifyParameters mParams = params[0];
				try {
					mResult = mIdentifyTask.execute(mParams);
				} catch (Exception e) {
					e.printStackTrace();
				}

			}
			return mResult;
		}

		@Override
		protected void onPostExecute(IdentifyResult[] results) {

			if (results != null && results.length > 0) {
				highlightGraphics = new Graphic[results.length];
				for (int i = 0; i < results.length; i++) {

					Geometry geom = results[i].getGeometry();// 得到几何对象
					String typeName = geom.getType().name();// 图层类型
					lightShow(i, typeName, geom);// 高亮显示

					IdentifyResult result = results[i];
					Log.i("andli", "图层名称---" + result.getLayerName());
					Log.i("andli", "图层id ---" + result.getLayerId());
					Log.i("andli", "图层类型---" + typeName);
				}
			} else {
				Toast.makeText(HighlightFeatures.this, "查询结果为空", 3000).show();
			}

		}

		@Override
		protected void onPreExecute() {
			mIdentifyTask = new IdentifyTask(mapURL);
		}

	}

	public void lightShow(int i, String typeName, Geometry geom) {
		// 高亮显示查询结果
		Random r = new Random();
		int color = Color.rgb(r.nextInt(255), r.nextInt(255), r.nextInt(255));// 生成随机色
		if (typeName.equalsIgnoreCase("point")) {
			SimpleMarkerSymbol sms = new SimpleMarkerSymbol(color, 20,
					STYLE.SQUARE);
			highlightGraphics[i] = new Graphic(geom, sms);
		} else if (typeName.equalsIgnoreCase("polyline")) {
			SimpleLineSymbol sls = new SimpleLineSymbol(color, 5);
			highlightGraphics[i] = new Graphic(geom, sls);
		} else if (typeName.equalsIgnoreCase("polygon")) {
			SimpleFillSymbol sfs = new SimpleFillSymbol(color);
			sfs.setAlpha(75);
			highlightGraphics[i] = new Graphic(geom, sfs);
		}

		graphicsLayer.addGraphic(highlightGraphics[i]);

	}
}
 

    
[3] alertdialog 应用系统选择时改变 默认字体大小
    来源: 互联网  发布时间: 2014-02-18
alertdialog 使用系统选择时改变 默认字体大小

ContextThemeWrapper ctw = new ContextThemeWrapper( getActivity(), R.style.AlertDialogCustom );
		Builder builder = new AlertDialog.Builder(btw);

  <style name="AlertDialogCustom" parent="@android:style/Theme.Dialog">
        <item name="android:textSize">15sp</item>
    </style>
 

    
最新技术文章:
▪Android开发之登录验证实例教程
▪Android开发之注册登录方法示例
▪Android获取手机SIM卡运营商信息的方法
▪Android实现将已发送的短信写入短信数据库的...
▪Android发送短信功能代码
▪Android根据电话号码获得联系人头像实例代码
▪Android中GPS定位的用法实例
▪Android实现退出时关闭所有Activity的方法
▪Android实现文件的分割和组装
▪Android录音应用实例教程
▪Android双击返回键退出程序的实现方法
▪Android实现侦听电池状态显示、电量及充电动...
▪Android获取当前已连接的wifi信号强度的方法
▪Android实现动态显示或隐藏密码输入框的内容
▪根据USER-AGENT判断手机类型并跳转到相应的app...
▪Android Touch事件分发过程详解
▪Android中实现为TextView添加多个可点击的文本
▪Android程序设计之AIDL实例详解
▪Android显式启动与隐式启动Activity的区别介绍
▪Android按钮单击事件的四种常用写法总结
▪Android消息处理机制Looper和Handler详解
▪Android实现Back功能代码片段总结
▪Android实用的代码片段 常用代码总结
▪Android实现弹出键盘的方法
▪Android中通过view方式获取当前Activity的屏幕截...
▪Android提高之自定义Menu(TabMenu)实现方法
▪Android提高之多方向抽屉实现方法
▪Android提高之MediaPlayer播放网络音频的实现方法...
▪Android提高之MediaPlayer播放网络视频的实现方法...
▪Android提高之手游转电视游戏的模拟操控
 


站内导航:


特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

©2012-2021,,E-mail:www_#163.com(请将#改为@)

docker中文入门学习手册 iis7站长之家