admin
2020-10-10 8039a1b2fbfa3471b6f726d3e839d7867c81a84f
BuWanVideo/src/com/weikou/beibeivideo/ui/recommend/SearchActivity.java
@@ -23,6 +23,7 @@
import android.widget.FrameLayout;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView;
import android.widget.Toast;
@@ -41,8 +42,9 @@
import com.weikou.beibeivideo.BasicTextHttpResponseHandler;
import com.weikou.beibeivideo.BeibeiVideoAPI;
import com.weikou.beibeivideo.ui.BaseActivity;
import com.weikou.beibeivideo.ui.video.SuggestKeysAdapter;
import com.weikou.beibeivideo.util.BeibeiConstant;
import com.yeshi.buwanshequ.R;
import com.weikou.beibeivideo.R;
import org.apache.http.Header;
import org.json.JSONObject;
@@ -54,15 +56,28 @@
    private AutoCompleteTextView et_search_key;
    private TextView tv_clear, tv_back;
    private TextView tv_clear;
    private ImageView tv_search_cancel;
    private TextView tv_search_cancel;
    private GridView gv_hot_search;
    private GridView gv_history_search;
    private LinearLayout ll_search_history;
    private String value = "";
    private void initView() {
        fl_advertisement = findViewById(R.id.fl_advertisement);
        et_search_key = findViewById(R.id.et_search_key);
        fl_advertisement.setOnClickListener(this);
        tv_search_cancel = findViewById(R.id.tv_search_cancel);
        gv_hot_search = findViewById(R.id.gv_hot_search);
        gv_history_search = findViewById(R.id.gv_history_search);
        tv_clear = findViewById(R.id.tv_search_clear_his);
        ll_search_history = findViewById(R.id.ll_search_history);
    }
    @Override
    protected void onCreate(Bundle savedInstanceState) {
@@ -84,26 +99,7 @@
        } else {
            findViewById(R.id.v_status_bar).setVisibility(View.GONE);
        }
        // findViewById(R.id.gv_video_guess_like).setVisibility(View.GONE);
        fl_advertisement = (FrameLayout) findViewById(R.id.fl_advertisement);
        et_search_key = (AutoCompleteTextView) findViewById(R.id.et_search_key);
        tv_back = (TextView) findViewById(R.id.tv_top_bar_left);
        tv_back.setOnClickListener(this);
        fl_advertisement.setOnClickListener(this);
        tv_search_cancel = (ImageView) findViewById(R.id.tv_search_cancel);
        gv_hot_search = (GridView) findViewById(R.id.gv_hot_search);
        gv_history_search = (GridView) findViewById(R.id.gv_history_search);
//      gv_video_guess_like = (GridView) findViewById(R.id.gv_video_guess_like);
        tv_clear = (TextView) (TextView) findViewById(R.id.tv_search_clear_his);
        // iv_search_ad = (ImageView) findViewById(R.id.iv_search_ad);// 聚效广告
        // WindowManager wm = (WindowManager) SearchActivity.this
        // .getSystemService(Context.WINDOW_SERVICE);
        // int width = wm.getDefaultDisplay().getWidth();
        // int height = (int) (width * (9.0f / 15.56f));
        // LayoutParams params = iv_search_ad.getLayoutParams();
        // params.width = width;
        // params.height = height;
        // iv_search_ad.setLayoutParams(params);
        initView();
        et_search_key.setOnEditorActionListener(new TextView.OnEditorActionListener() {
            @Override
@@ -249,6 +245,7 @@
    @Override
    public void onResume() {
        super.onResume();
        getHistorySearch();
        MobclickAgent.onPageStart("搜索页");
    }
@@ -261,25 +258,9 @@
    @Override
    public void onClick(final View v) {
        switch (v.getId()) {
            case R.id.tv_search_cancel: {
//         if (tv_search_cancel.getText().toString()
//               .equals(getResources().getString(R.string.search))) {
                Intent intent = new Intent(this, SearchResultActivity.class);
                if (StringUtils.isEmpty(et_search_key.getEditableText()
                        .toString()) && (et_search_key.getHint() == null || StringUtils.isEmpty(et_search_key.getHint().toString()))) {
                    Toast.makeText(SearchActivity.this, "请输入搜索内容!", Toast.LENGTH_LONG).show();
                    return;
                } else {
                    intent.putExtra("key", StringUtils.isEmpty(et_search_key.getEditableText()
                            .toString()) ? et_search_key.getHint().toString() : et_search_key.getEditableText()
                            .toString());
                }
                startActivity(intent);
//         } else {
//            finish();
//         }
            }
            break;
            case R.id.tv_search_cancel:
                finish();
                break;
            case R.id.tv_search_clear_his:
                clearHistorySearch();
                break;
@@ -310,10 +291,8 @@
                                    .getJSONObject("Data").getJSONArray("data")
                                    .toString(), new TypeToken<List<String>>() {
                            }.getType());
                            ArrayAdapter<String> adapter = new ArrayAdapter<String>(
                                    SearchActivity.this,
                                    android.R.layout.simple_list_item_1,
                                    results);
                            SuggestKeysAdapter adapter = new SuggestKeysAdapter(getApplicationContext(), results);
                            et_search_key.setAdapter(adapter);
                            adapter.notifyDataSetChanged();
                        }
@@ -325,14 +304,19 @@
        SharedPreferences historySp = getSharedPreferences("search_history",
                Context.MODE_PRIVATE);
        String historyStr = historySp.getString("history", "");
        String[] historyArray = historyStr.split(",");
        List<String> history = new ArrayList<String>();
        for (int i = 0; i < 10 && i < historyArray.length; i++) {
            if (!TextUtils.isEmpty(historyArray[historyArray.length - 1 - i])) {
                history.add(historyArray[historyArray.length - 1 - i]);
        if (!StringUtils.isBlank(historyStr)) {
            String[] historyArray = historyStr.split(",");
            ll_search_history.setVisibility(View.VISIBLE);
            List<String> history = new ArrayList<String>();
            for (int i = 0; i < 10 && i < historyArray.length; i++) {
                if (!TextUtils.isEmpty(historyArray[historyArray.length - 1 - i])) {
                    history.add(historyArray[historyArray.length - 1 - i]);
                }
            }
            gv_history_search.setAdapter(new GridSuggestionAdapter(history, false));
        } else {
            ll_search_history.setVisibility(View.GONE);
        }
        gv_history_search.setAdapter(new GridSuggestionAdapter(history, false));
    }
    private void clearHistorySearch() {
@@ -380,7 +364,7 @@
                BeibeiConstant.GDT_ID, BeibeiConstant.GDT_SEARCH_NATIVE, new NativeExpressAD.NativeExpressADListener() {
            @Override
            public void onADLoaded(final List<NativeExpressADView> list) {
                tv_back.post(new Runnable() {
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        if (null != list && list.size() > 0) {